Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2005-05-02 04:33:50

"Eric Niebler" <eric_at_[hidden]> wrote

> I suppose you could say that case 2 can always be handled with a set of
> parens, as in:
> BOOST_FOREACH( int i, (some_trait<this,that>::some_list()) )
> Therefore, all macro args but the last should be interpreted as part of the
> loop variable declaration.

I have used the BOOST_FOREACH macro and its ok. As its main raison d'aitre is
brevity, why do I need to explicitly provide the loop variable.I would hope for
something like:

FOREACH(my_container){ std::cout << *_ << '\n'; }

IOW the boost::lambda placeholders could be used. Is not foreach a subset of
the lambda functionality. (Proponents of lambda always cite this is an example.)

I dont know of a reason to require conversions as in the example:
short array_short[] = {1,2,3};
BOOST_FOREACH( int i, array_short )
    // The short was implicitly converted to an int
What is the point of the example?

FWIW A naive method to do the above is as:

#define FOR_EACH(cont) \
    for (BOOST_TYPEOF( cont )>::iterator _ = cont ## .begin();\
            _ != cont ## .end();\
            ++ _ )

exept require *_ as opposed to _

However maybe this is an advantage... because the iterator is exposed then more
loop information is avaialable eg if _ == my_container::begin() etc., which is
an advantage over simply having the element available so making things more

Andy Little

Boost list run by bdawes at, gregod at, cpdaniel at, john at