Re: [boost] Re: Formal Review: FOREACH macro

In-Reply-To: <d55q7o$4g5$1@sea.gmane.org> SeeWebsiteForEmail@moderncppdesign.com (Andrei Alexandrescu (See Website For Email)) wrote (abridged):
Comparing:
BOOST_FOREACH( int i, vec ) cout << i;
with:
for (iterator i = vec.begin(); i != vec.end(); ++i) cout << *i;
the macro just doesn't seem worth it.
In fairness, it's
for (vector<ArbitrarilyComplexType>::iterator i = vec.begin(); i != vec.end(); ++i) cout << *i;
No, I meant what I wrote. I usually have a suitable iterator typedef in scope. In the worst case it is more like: typedef vector<ArbitrarilyComplexType> MyVec; for (MyVec::iterator i = vec.begin(); i != vec.end(); ++i) cout << *i; where "MyVec" is some meaningful name (and is probably itself worth putting at some larger scope - after all, where did the vec come from?). And I see adding a typedef as clearer, transparent even, compared to the BOOST_FOREACH macro.
I think the part of the discussion that focuses on arguments for or against macros is misplaced.
Agreed. As I said earlier, I am not absolutely against macros; I won't automatically vote against any proposal that uses them. I am also objecting to BOOST_FOREACH because it is taking something simple and making it complicated. -- Dave Harris, Nottingham, UK.

Dave Harris wrote:
No, I meant what I wrote. I usually have a suitable iterator typedef in scope. In the worst case it is more like:
typedef vector<ArbitrarilyComplexType> MyVec; for (MyVec::iterator i = vec.begin(); i != vec.end(); ++i) cout << *i;
But we sometimes have containers of boost::shared_ptr which then requires (*i)-> to access. BOOST_FOREACH simplifies these cases. Cheers Russell
participants (2)
-
brangdon@cix.compulink.co.uk
-
Russell Hind