Chapter 5: Lambda Expressions
The C++11 standard introduced the lambda expression (sometimes called the lambda function, or just lambda). This feature allows an anonymous function to be used in the context of an expression. Lambdas may be used in function calls, containers, variables, and other expression contexts. It may sound innocuous, but it's remarkably useful.
Let's start with a brief review of lambda expressions.
Lambda expressions
A lambda is essentially an anonymous function as a literal expression:
auto la = []{ return "Hello\n"; };
The variable la may now be used as if it were a function:
cout << la();
It can be passed to another function:
f(la);
It can be passed to another lambda:
const auto la = []{ return "Hello\n"; };
const auto ...
Get C++20 STL Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.