terça-feira, 10 de janeiro de 2012

Lambda expressions in C++0x / C++11

The new C++ standard C++11 (formerly known as C++0x) has support for Lambda expressions, which makes it easier to write callback-functions. 
For example, the code below sorts the array "employees" on the member "name", without having to create a sort function/class.
std::sort(employees.begin(), employees .end(),
[&](int a, int b) { return v[a].name<v[b].name; });

This code has been successfully tested on Microsoft Visual Studio 2010 (Visual C++ 10) and Netbeans 7.0.

Nenhum comentário:

Postar um comentário