Boost logo

Boost :

Subject: Re: [boost] tie alternative?
From: David Abrahams (dave_at_[hidden])
Date: 2008-10-28 10:13:17


on Tue Oct 28 2008, Thorsten Ottosen <thorsten.ottosen-AT-dezide.com> wrote:

> Benoit skrev:
>>> OK, BOOST_FOREACH aside, iterating over a range returned as a pair of
>>> iterators can be painful and ugly:
>>
>> I have encountered the same problem, but i am not sure why you would
>> want to use anything but BOOST_FOREACH...
>>
>>> for (vertex_iterator pv,ve = xxx(pv,vertices(g)); pv != ve; ++pv)
>> Moreover, in my opinion, the above construct seems a bit awkward to
>> me. Modifying pv and pe at the same time, one as a function parameter,
>> the other initialized with what the functions returns is a best very
>> confusing. It's very clever, though, but again, why not use
>> BOOST_FOREACH ?
>>
>> Another idea might be to directly use a pair of iterators by creating
>> a special structure for "duplicate pairs"...
>>
>> for( duplicate_pair<vertex_iterator> vip( vertices( g ) ) ; vip.first
>> != vip.second ; ++vip.first )
>> {
>> //...
>> }
>>
>> I am not sure there's a real gain here though. Oh well. Can't blame me
>> for trying ! :-)
>
> FWIW, You can already today do
>
> for( boost::iterator_range<vertex_iterator> vip( vertices( g ) ) ;
> !vip.empty(); vip.advance_begin(1) )

It's sad, but I'm not as confident in the ability to optimize that form
because the iterators are bundled into a single struct. Also I am not
fond of the constant 1.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk