
John Torjo wrote:
michael toksvig wrote:
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;
You can also use the rtl (Ranges Template Library): (note: I'll rename the library, wince there's another one with the same name ;))
for( crange<container> r(cont); r; ++r) *r += 2;
p.s. no macros involved in the above statement ;) Best, John