tmp/tmpm7o_wm7_/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### General <a id="expr.prim.lambda.general">[[expr.prim.lambda.general]]</a>
|
| 2 |
+
|
| 3 |
+
``` bnf
|
| 4 |
+
lambda-expression:
|
| 5 |
+
lambda-introducer attribute-specifier-seqₒₚₜ lambda-declarator compound-statement
|
| 6 |
+
lambda-introducer '<' template-parameter-list '>' requires-clauseₒₚₜ attribute-specifier-seqₒₚₜ
|
| 7 |
+
lambda-declarator compound-statement
|
| 8 |
+
```
|
| 9 |
+
|
| 10 |
+
``` bnf
|
| 11 |
+
lambda-introducer:
|
| 12 |
+
'[' lambda-captureₒₚₜ ']'
|
| 13 |
+
```
|
| 14 |
+
|
| 15 |
+
``` bnf
|
| 16 |
+
lambda-declarator:
|
| 17 |
+
lambda-specifier-seq noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
|
| 18 |
+
noexcept-specifier attribute-specifier-seqₒₚₜ trailing-return-typeₒₚₜ
|
| 19 |
+
trailing-return-typeₒₚₜ
|
| 20 |
+
'(' parameter-declaration-clause ')' lambda-specifier-seqₒₚₜ noexcept-specifierₒₚₜ attribute-specifier-seqₒₚₜ
|
| 21 |
+
trailing-return-typeₒₚₜ requires-clauseₒₚₜ
|
| 22 |
+
```
|
| 23 |
+
|
| 24 |
+
``` bnf
|
| 25 |
+
lambda-specifier:
|
| 26 |
+
consteval
|
| 27 |
+
constexpr
|
| 28 |
+
mutable
|
| 29 |
+
static
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
``` bnf
|
| 33 |
+
lambda-specifier-seq:
|
| 34 |
+
lambda-specifier
|
| 35 |
+
lambda-specifier lambda-specifier-seq
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
A *lambda-expression* provides a concise way to create a simple function
|
| 39 |
+
object.
|
| 40 |
+
|
| 41 |
+
[*Example 1*:
|
| 42 |
+
|
| 43 |
+
``` cpp
|
| 44 |
+
#include <algorithm>
|
| 45 |
+
#include <cmath>
|
| 46 |
+
void abssort(float* x, unsigned N) {
|
| 47 |
+
std::sort(x, x + N, [](float a, float b) { return std::abs(a) < std::abs(b); });
|
| 48 |
+
}
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
— *end example*]
|
| 52 |
+
|
| 53 |
+
A *lambda-expression* is a prvalue whose result object is called the
|
| 54 |
+
*closure object*.
|
| 55 |
+
|
| 56 |
+
[*Note 1*: A closure object behaves like a function object
|
| 57 |
+
[[function.objects]]. — *end note*]
|
| 58 |
+
|
| 59 |
+
An ambiguity can arise because a *requires-clause* can end in an
|
| 60 |
+
*attribute-specifier-seq*, which collides with the
|
| 61 |
+
*attribute-specifier-seq* in *lambda-expression*. In such cases, any
|
| 62 |
+
attributes are treated as *attribute-specifier-seq* in
|
| 63 |
+
*lambda-expression*.
|
| 64 |
+
|
| 65 |
+
[*Note 2*: Such ambiguous cases cannot have valid semantics because the
|
| 66 |
+
constraint expression would not have type `bool`. — *end note*]
|
| 67 |
+
|
| 68 |
+
A *lambda-specifier-seq* shall contain at most one of each
|
| 69 |
+
*lambda-specifier* and shall not contain both `constexpr` and
|
| 70 |
+
`consteval`. If the *lambda-declarator* contains an explicit object
|
| 71 |
+
parameter [[dcl.fct]], then no *lambda-specifier* in the
|
| 72 |
+
*lambda-specifier-seq* shall be `mutable` or `static`. The
|
| 73 |
+
*lambda-specifier-seq* shall not contain both `mutable` and `static`. If
|
| 74 |
+
the *lambda-specifier-seq* contains `static`, there shall be no
|
| 75 |
+
*lambda-capture*.
|
| 76 |
+
|
| 77 |
+
[*Note 3*: The trailing *requires-clause* is described in
|
| 78 |
+
[[dcl.decl]]. — *end note*]
|
| 79 |
+
|
| 80 |
+
If a *lambda-declarator* does not include a
|
| 81 |
+
*parameter-declaration-clause*, it is as if `()` were inserted at the
|
| 82 |
+
start of the *lambda-declarator*. If the *lambda-declarator* does not
|
| 83 |
+
include a *trailing-return-type*, it is considered to be `-> auto`.
|
| 84 |
+
|
| 85 |
+
[*Note 4*: In that case, the return type is deduced from `return`
|
| 86 |
+
statements as described in [[dcl.spec.auto]]. — *end note*]
|
| 87 |
+
|
| 88 |
+
[*Example 2*:
|
| 89 |
+
|
| 90 |
+
``` cpp
|
| 91 |
+
auto x1 = [](int i) { return i; }; // OK, return type is int
|
| 92 |
+
auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from braced-init-list
|
| 93 |
+
int j;
|
| 94 |
+
auto x3 = [&]()->auto&& { return j; }; // OK, return type is int&
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
— *end example*]
|
| 98 |
+
|
| 99 |
+
A lambda is a *generic lambda* if the *lambda-expression* has any
|
| 100 |
+
generic parameter type placeholders [[dcl.spec.auto]], or if the lambda
|
| 101 |
+
has a *template-parameter-list*.
|
| 102 |
+
|
| 103 |
+
[*Example 3*:
|
| 104 |
+
|
| 105 |
+
``` cpp
|
| 106 |
+
int i = [](int i, auto a) { return i; }(3, 4); // OK, a generic lambda
|
| 107 |
+
int j = []<class T>(T t, int i) { return i; }(3, 4); // OK, a generic lambda
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
— *end example*]
|
| 111 |
+
|