C++ getting lambdas and closures
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++.
Mar 29 2008
10:14 pm
Most of C++0x is here already; Boost 1.3.5 was released today, and has had lambdas for quite some time.
Anyone who complains about C++0x being a bloat on top of a bloated language really… Just… Isn’t worth arguing with.
It’s a toolset. You don’t use a wrench to hammer in a nail, but it’s nice to keep it around.
And C++ wrenches are ratched, though you can still bust off a finger with the hammer.
Ah, shop analogies.