The entities that are
captured by copy are used to direct-initialize each corresponding non-static data member
of the resulting closure object
. The non-static data members corresponding to the
init-captures
and the (reference) variables declared by
init-captures
without corresponding non-static data members
are initialized as indicated by the corresponding
initializer
(which may be copy- or direct-initialization)
. (For array members, the array elements are direct-initialized in increasing subscript order
.)
These initializations are performed
when the
lambda-expression is evaluated,
in an order consistent with the (partially unspecified) order
in which the non-static data members are declared
and with the order of explicit captures
. [
Note 9:
This ensures that the destructions will occur in the reverse order of the constructions
. —
end note]
[
Example 12:
void f(std::vector<int> &&v) {
[size = v.size(), own = std::move(v)] {};
}
Since
size is initialized before
own,
it contains the original size of
v. —
end example]