An anonymous function (also function literal or lambda abstraction) is a function definition that is not bound to an identifier.
C++ (since C++11)
C++11 provides support for anonymous functions, called lambda expressions. A lambda expression has the form:
[capture](parameters) -> return_type { function_body }
Example
#include <string>
#include <cctype>
#include <algorithm>
#include <iostream>
int main()
{
std::string s("hello");
std::transform(s.begin(), s.end(), s.begin(),
[](unsigned char c) { return std::toupper(c); });
std::cout << s;
}
近期评论