C++ getting lambdas and closures

March 29, 2008 • 30 sec read


This post is over ten years old. Chances are, I've learned enough to have advanced my thinking about some of this stuff.

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++.


Liked this? Follow along to see what's next.

© Allen Pike. 👋🏼 You can contact me, or check out Steamclock.