When I write a lambda with [=]
, does it mean that all my local variables will be copied into members of the created struct or can I assume that only those will that are actually used in the lambda? For example:
void f()
{
vector<int> v(10000);
const int n = 5;
const int DivByNCnt = count_if(istream_iterator<int>(cin), istream_iterator<int>(),
[=](int i)
{
return i % n == 0;
});
}
Which of the following, if any, is true?
- both n and v will be copied
- n will be copied, v will not
- n will be copied, v may or may not be copied depending on the implmenentation/optimization settings.
Suppose for the argument's sake that vector's copy constructor has side effects.