Linked by Eugenia Loli on Mon 1st Aug 2005 00:05 UTC
General Development Don't be jealous of programmers using new languages, such as Python or C#! C++ gives you many ways to iterate through data you've stored in containers, supports for-each, and has helpful devices called lambda functions. Jeff Cogswell shows you how you can fly through your containers with ease.
Permalink for comment 12101
To read all comments associated with this story, please click here.
by eric_niebler on Mon 1st Aug 2005 16:03 UTC
Member since:

A foreach looping macro was recently accepted into Boost ( ). It works with STL containers, arrays, and iterator ranges, and it doesn't require the compiler to support typeof or auto, so it works on older compilers. It even allows you to mutate the sequence in place:

int array[] = {1,2,3,4};
BOOST_FOREACH(int & i, array)
// array is now {2,3,4,5}

The docs are at .

You can download the code ( at .

The code requires Boost 1.32.

Eric Niebler
Boost Consulting

Reply Score: 1