Boost logo

Boost Users :

Subject: Re: [Boost-users] BOOST_FOREACH with Index
From: Eric Niebler (eric_at_[hidden])
Date: 2009-12-13 21:27:37


Nat Goodspeed wrote:
> Eric Niebler wrote:
>
>>>> Why not:
>>>>
>>>> int index = 0;
>>>>
>>>> BOOST_FOREACH(const Foo &f, foos)
>>>> {
>>>> // ... stuff ...
>>>> ++index;
>>>> }
>
>> What value BOOST_FOREACH has comes primarily from its ability to
>> simplify something that's already pretty darn simple -- a plain
>> for(;;) loop. I strongly resist any effort to make BOOST_FOREACH more
>> complicated, unless the wins are truly significant. In this case, I
>> don't think they are.
>
> Maybe this shouldn't be a BOOST_FOREACH feature at all. As with Python's
> builtin enumerate() function, maybe what we want here is an iterator
> adapter that dereferences to a std::pair<index_type,
> original_iterator_value_type>?

This would fit in well with the proposed resolution of
https://svn.boost.org/trac/boost/ticket/3469. I'll reference this
discussion from that ticket. Thanks for the suggestion.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net