
2 May
2005
2 May
'05
3:29 p.m.
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