Date: 2016-06-27Thomas Köppe <email@example.com>
ISO/IEC JTC1 SC22 WG21 P0409R0
We propose to allow
[=, this] as a lambda capture.
With the introduction of capture-
this-by-value in C++17, it may be
desirable to increase code readability by being explicit about the kind of capture
in the presence of a
By contrast, when both
[=, *this] are present
in a code base in large numbers, it may be easy to forget that the former is different
from the latter: It is hard to notice the absence of something. In such situations, authors
may wish to be explicit and to spare the reader from having remember the correct default.
The proposal is a pure core language extension. The newly allowed syntax was previously ill-formed.
In section 5.1.5 [expr.prim.lambda], change paragraph 9 as follows.
If a lambda-capture includes a capture-default that is
no identifier in a simple-capture of that lambda-capture shall be preceded
&. If a lambda-capture includes a capture-default that
=, each simple-capture of that lambda-capture shall be of
the form “
* this”. [Note: The form
[&, this] is
redundant but accepted for compatibility with ISO C++ 2014. – end note]
Ignoring appearances in initializers of init-captures, an identifier or
shall not appear more than once in a lambda-capture. [Example:
– end example]