|
Boost Users : |
Subject: Re: [Boost-users] BOOST_FOREACH with Index
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-12-13 21:11:50
On Sun, Dec 13, 2009 at 6:41 PM, Nat Goodspeed <nat_at_[hidden]> 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>?
Ooo, that makes sense, as long as it can still be done quickly (ala
the in index = 0; example above):
BOOST_FOREACH(size_t i, const Foo &f, ENUMERATE(foos))
Or maybe:
BOOST_FOREACH_ENUMERATE(size_t i, const Foo &f, foos)
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