When I write lambda with [=] , does this mean that all my local variables will be copied to the members of the created structure, or can I assume that only those that are really used in 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?
- and 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 implantation / optimization settings.
Suppose for an argument that a vector copy constructor has side effects.
c ++ lambda c ++ 11 capture
Armen Tsirunyan Mar 25 '13 at 10:19 2013-03-25 10:19
source share