
14 Dec
2009
14 Dec
'09
1:41 a.m.
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