vector v(10);
generate(v.begin(), v.end(), rand);
for_each(v.begin(), v.end(),
[](int& x){ cout << x << " ";});
OK, so the syntax looks a bit strange at first, but it does add a powerful construct to the language.
Lambdas have only just been added to the C++0x standard and support for lambdas are not included in the beta version of the Visual Studio 2008 TR1 feature pack.
For more details and examples of lambda functions, check out Herb Sutter's recent trip report from the February/March ISO C++ standards meeting.
No comments:
Post a Comment