tmp/tmpz874b7ss/{from.md → to.md}
RENAMED
|
@@ -28,30 +28,30 @@ capture:
|
|
| 28 |
``` bnf
|
| 29 |
simple-capture:
|
| 30 |
identifier '...'ₒₚₜ
|
| 31 |
'&' identifier '...'ₒₚₜ
|
| 32 |
this
|
| 33 |
-
'*'
|
| 34 |
```
|
| 35 |
|
| 36 |
``` bnf
|
| 37 |
init-capture:
|
| 38 |
'...'ₒₚₜ identifier initializer
|
| 39 |
'&' '...'ₒₚₜ identifier initializer
|
| 40 |
```
|
| 41 |
|
| 42 |
The body of a *lambda-expression* may refer to local entities of
|
| 43 |
-
enclosing
|
| 44 |
|
| 45 |
If a *lambda-capture* includes a *capture-default* that is `&`, no
|
| 46 |
identifier in a *simple-capture* of that *lambda-capture* shall be
|
| 47 |
preceded by `&`. If a *lambda-capture* includes a *capture-default* that
|
| 48 |
is `=`, each *simple-capture* of that *lambda-capture* shall be of the
|
| 49 |
form “`&` *identifier* `...`ₒₚₜ ”, “`this`”, or “`* this`”.
|
| 50 |
|
| 51 |
[*Note 1*: The form `[&,this]` is redundant but accepted for
|
| 52 |
-
compatibility with
|
| 53 |
|
| 54 |
Ignoring appearances in *initializer*s of *init-capture*s, an identifier
|
| 55 |
or `this` shall not appear more than once in a *lambda-capture*.
|
| 56 |
|
| 57 |
[*Example 1*:
|
|
@@ -70,14 +70,19 @@ void S2::f(int i) {
|
|
| 70 |
```
|
| 71 |
|
| 72 |
— *end example*]
|
| 73 |
|
| 74 |
A *lambda-expression* shall not have a *capture-default* or
|
| 75 |
-
*simple-capture* in its *lambda-introducer* unless
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
The *identifier* in a *simple-capture* shall denote a local entity
|
| 81 |
[[basic.lookup.unqual]], [[basic.pre]]. The *simple-capture*s `this` and
|
| 82 |
`* this` denote the local entity `*this`. An entity that is designated
|
| 83 |
by a *simple-capture* is said to be *explicitly captured*.
|
|
@@ -295,11 +300,12 @@ void f2() {
|
|
| 295 |
An entity is *captured by copy* if
|
| 296 |
|
| 297 |
- it is implicitly captured, the *capture-default* is `=`, and the
|
| 298 |
captured entity is not `*this`, or
|
| 299 |
- it is explicitly captured with a capture that is not of the form
|
| 300 |
-
`this`, `&` *identifier*, or `&` *identifier*
|
|
|
|
| 301 |
|
| 302 |
For each entity captured by copy, an unnamed non-static data member is
|
| 303 |
declared in the closure type. The declaration order of these members is
|
| 304 |
unspecified. The type of such a data member is the referenced type if
|
| 305 |
the entity is a reference to an object, an lvalue reference to the
|
|
@@ -326,11 +332,11 @@ the closure type.
|
|
| 326 |
``` cpp
|
| 327 |
void f(const int*);
|
| 328 |
void g() {
|
| 329 |
const int N = 10;
|
| 330 |
[=] {
|
| 331 |
-
int arr[N]; // OK, not an odr-use, refers to automatic
|
| 332 |
f(&N); // OK, causes N to be captured; &N points to
|
| 333 |
// the corresponding member of the closure type
|
| 334 |
};
|
| 335 |
}
|
| 336 |
```
|
|
|
|
| 28 |
``` bnf
|
| 29 |
simple-capture:
|
| 30 |
identifier '...'ₒₚₜ
|
| 31 |
'&' identifier '...'ₒₚₜ
|
| 32 |
this
|
| 33 |
+
'*' this
|
| 34 |
```
|
| 35 |
|
| 36 |
``` bnf
|
| 37 |
init-capture:
|
| 38 |
'...'ₒₚₜ identifier initializer
|
| 39 |
'&' '...'ₒₚₜ identifier initializer
|
| 40 |
```
|
| 41 |
|
| 42 |
The body of a *lambda-expression* may refer to local entities of
|
| 43 |
+
enclosing scopes by capturing those entities, as described below.
|
| 44 |
|
| 45 |
If a *lambda-capture* includes a *capture-default* that is `&`, no
|
| 46 |
identifier in a *simple-capture* of that *lambda-capture* shall be
|
| 47 |
preceded by `&`. If a *lambda-capture* includes a *capture-default* that
|
| 48 |
is `=`, each *simple-capture* of that *lambda-capture* shall be of the
|
| 49 |
form “`&` *identifier* `...`ₒₚₜ ”, “`this`”, or “`* this`”.
|
| 50 |
|
| 51 |
[*Note 1*: The form `[&,this]` is redundant but accepted for
|
| 52 |
+
compatibility with C++14. — *end note*]
|
| 53 |
|
| 54 |
Ignoring appearances in *initializer*s of *init-capture*s, an identifier
|
| 55 |
or `this` shall not appear more than once in a *lambda-capture*.
|
| 56 |
|
| 57 |
[*Example 1*:
|
|
|
|
| 70 |
```
|
| 71 |
|
| 72 |
— *end example*]
|
| 73 |
|
| 74 |
A *lambda-expression* shall not have a *capture-default* or
|
| 75 |
+
*simple-capture* in its *lambda-introducer* unless
|
| 76 |
+
|
| 77 |
+
- its innermost enclosing scope is a block scope [[basic.scope.block]],
|
| 78 |
+
- it appears within a default member initializer and its innermost
|
| 79 |
+
enclosing scope is the corresponding class scope
|
| 80 |
+
[[basic.scope.class]], or
|
| 81 |
+
- it appears within a contract assertion and its innermost enclosing
|
| 82 |
+
scope is the corresponding contract-assertion scope
|
| 83 |
+
[[basic.scope.contract]].
|
| 84 |
|
| 85 |
The *identifier* in a *simple-capture* shall denote a local entity
|
| 86 |
[[basic.lookup.unqual]], [[basic.pre]]. The *simple-capture*s `this` and
|
| 87 |
`* this` denote the local entity `*this`. An entity that is designated
|
| 88 |
by a *simple-capture* is said to be *explicitly captured*.
|
|
|
|
| 300 |
An entity is *captured by copy* if
|
| 301 |
|
| 302 |
- it is implicitly captured, the *capture-default* is `=`, and the
|
| 303 |
captured entity is not `*this`, or
|
| 304 |
- it is explicitly captured with a capture that is not of the form
|
| 305 |
+
`this`, `&` *identifier* `...`ₒₚₜ , or `&` `...`ₒₚₜ *identifier*
|
| 306 |
+
*initializer*.
|
| 307 |
|
| 308 |
For each entity captured by copy, an unnamed non-static data member is
|
| 309 |
declared in the closure type. The declaration order of these members is
|
| 310 |
unspecified. The type of such a data member is the referenced type if
|
| 311 |
the entity is a reference to an object, an lvalue reference to the
|
|
|
|
| 332 |
``` cpp
|
| 333 |
void f(const int*);
|
| 334 |
void g() {
|
| 335 |
const int N = 10;
|
| 336 |
[=] {
|
| 337 |
+
int arr[N]; // OK, not an odr-use, refers to variable with automatic storage duration
|
| 338 |
f(&N); // OK, causes N to be captured; &N points to
|
| 339 |
// the corresponding member of the closure type
|
| 340 |
};
|
| 341 |
}
|
| 342 |
```
|