[expr.prim.lambda.general] (original) (raw)
7 Expressions [expr]
7.5 Primary expressions [expr.prim]
7.5.5 Lambda expressions [expr.prim.lambda]
7.5.5.1 General [expr.prim.lambda.general]
A lambda-expression provides a concise way to create a simple function object.
[Example 1: #include <algorithm> #include <cmath> void abssort(float* x, unsigned N) { std::sort(x, x + N, [](float a, float b) { return std::abs(a) < std::abs(b); });} — _end example_]
A lambda-expression is a prvalue whose result object is called the closure object.
If a lambda-expression does not include alambda-declarator, it is as if the lambda-declarator were().
The lambda return type is auto, which is replaced by the type specified by thetrailing-return-type if provided and/or deduced fromreturn statements as described in [dcl.spec.auto].
[Example 2: auto x1 = [](int i){ return i; }; auto x2 = []{ return { 1, 2 }; }; int j;auto x3 = []()->auto&& { return j; }; — _end example_]
[Example 3: int i = [](int i, auto a) { return i; }(3, 4); int j = []<class T>(T t, int i) { return i; }(3, 4); — _end example_]