|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2003-10-09 22:15:35
On Thursday 09 October 2003 03:05 pm, Eric Niebler wrote:
> To recap, I'm suggesting the addition of BOOST_FOREACH to make it
> trivial to write loops over sequences and containers of various sorts.
>
> Typical usage:
> std::list<int> int_list;
> ...
> BOOST_FOREACH( int &i, int_list )
> {
> // mutates the int in the list:
> i += 20;
> // break works as you would expect
> if ( i == 100 )
> break;
> }
I either love it, or I hate it, but I can't tell which :)
It looks technically sound, and I have no worries about that. I almost said
that I prefer std::for_each, but that's not always true: there are some
things that are just too hard to write inline with lambda/bind, too trivial
to make into a separate function object (even though I'm a _huge_ fan of
doing that), and writing the darned 'for' loop takes up two lines because
'const_iterator' and 'typename' are so darned long.
So overall I think I might like it. I gripe about macros as much as the next
guy, but I do think there are cases where BOOST_FOREACH is cleaner than any
of the alternatives.
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk