Quick Q: Does [=] capture all variables in scope? -- StackOverflow

Quick A: No.

A simple but important question:

C++11 lambda capture semantics

When I use [=] to indicate that I would like all local variables to be captured by value in a lambda, will that result in all local variables in the function being copied, or just all local variables that are used by the lambda?

So, for example, if I have:

vector<int> my_huge_vector(100000);
int my_measly_int;
some_function([=](int i){ return my_measly_int + i; });

Will my_huge_vector be copied, even though I don't use it in the lambda?

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.