C++ getting lambdas and closures

March 29, 2008

I’ve been following the evolving C++0x standard, and although it’s been adding a lot of new features, I didn’t expect this one: lambdas and closure syntax. Well, more like existing C++ syntax forged into lambdas and closures.

// Writing a collection to cout, in C++0x:
for_each( w.begin(), w.end(),
                [](const Widget& w) {cout << w << " ";} );

Some think that C++0x is adding excess complexity into an excessively complex language. That may be so, but man it would be nice to be able to use some of these features as a game developer restricted to C++.

© Allen Pike. See also Twitter and Steamclock.