Boost logo

Boost :

From: michael toksvig (michaeltoksvig_at_[hidden])
Date: 2004-04-20 10:29:03


A while back, Erik Niebler was testing the waters for inclusion of his very,
very clever looping construct into boost, but nothing really came of it.

Erik's technique is described here:
    http://www.nwcpp.org/Meetings/2004/01.html

Yup, macros are involved and they are yucky, and yup, there already exists a
for_each in the standard that works just fine if you care to move your loop
body away into a function, and yup, the name BOOST_FOREACH could use a
little love.

But there is no denying the notational clarity and succinctness of e.g.:
    foreach(double &d, container)
        d += 2;

Versus the rather redundant:
    for (list<double>::iterator i = container.begin(); i !=container.end();
++i)
        *i += 2;

(Note that the latter stops working if container is represented using a
vector or a built-in array instead)

/Michael Toksvig


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