Why compiler can’t understand in
foo1
that all I need it to capturef
by value since it is the only variable in used in lambda? Why this must be explicitly stated as infoo2
?
You need to declare variable lambda in order to capture.
Snippet:
void foo1() {
double d = 1.0;
auto lambda = [=, &d]() { d = double(f); };
lambda();
}
void foo2() {
double d = 1.0;
auto lambda = [f=f, &d]() { d = double(f); };
lambda();
}