I understand the correct way to capture this
(to modify object properties) in a lambda is as follows:
auto f = [this] () { /* ... */ };
<
Because standard doesn't have &this
in Captures lists:
N4713 8.4.5.2 Captures:
lambda-capture:
capture-default
capture-list
capture-default, capture-list
capture-default:
&
=
capture-list:
capture...opt
capture-list, capture...opt
capture:
simple-capture
init-capture
simple-capture:
identifier
&identifier
this
* this
init-capture:
identifier initializer
&identifier initializer
For the purposes of lambda capture, an expression potentially references local entities as follows:
7.3 A this expression potentially references *this.
So, standard guarantees this
and *this
is valid, and &this
is invalid. Also, capturing this
means capturing *this
(which is a lvalue, the object itself) by reference, rather than capturing this
pointer by value!