Boost logo

Boost :

From: Andrei Alexandrescu (See Website For Email) (SeeWebsiteForEmail_at_[hidden])
Date: 2005-05-02 13:13:01

Dave Harris wrote:
> 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;

And add to that that for is more general (in potentially harmful ways)
because the iterator can be freely modified inside the loop. Often,
that's not what you wanna.

I don't like macros myself (ack! chaos! nooooo!...), but IMHO it's
unfair to label FOREACH as macro-heavy machinery. The macro is but one
layer behind which there's good non-macro stuff.

I think the part of the discussion that focuses on arguments for or
against macros is misplaced. We should ask ourselves about abstraction.
That's the good thing. Does BOOST_FOREACH offer a good abstraction? Dave
Harris says it's not enough, and I think that's the proper focus of
discussion. (As a contrast, think of the boost initialization library. I
doesn't use macros but I consider it way more dangerous, less useful,
and offering less of an abstraction.) I think BOOST_FOREACH does offer a
good, useful abstraction, that the disadvantages ot it using a macro are
assuaged by good handling of macro-related problems and good taste in
design, so if I have voting power around here, I'd vote for :o).


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