Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2005-05-02 10:29:43


Andy Little wrote:
>
> #define FOR_EACH(cont) \
> for (BOOST_AUTO( _ , boost::begin(cont) );\
> _ != boost::end(cont);\
> ++ _ )
>
<snip>
>
> Are there advantages to the BOOST_FOREACH approach?
>

Yes. BOOST_TYPEOF and BOOST_AUTO require types to be registered.
BOOST_FOREACH does not. BOOST_AUTO is also a large dependency, and will
induce large compile times unnecessarily.

Also, your code doesn't work if "cont" is an unnamed temporary, and it
will cause "cont" to be reevaluated multiple times.

In short, the complexity of BOOST_FOREACH is needed to make it work as
much like a keyword as possible.

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk