std::function<int()> void f1()
{
int a, b, c, d, ..., x, y, z;
return [=] { return a + b + c; };
}
vs.
std::function<int()> void f2()
{
int a, b, c, d, ..., x, y, z;
return [a, b, c] { return a + b + c; };
}
Needless to say, the former is shorter, handier, and more elegant than the latter.
However, I still worry:
From the performance viewpoint, is the latter always better than the former?
Does the standard guarantee a lambda expression captures the necessary variables only? i.e. In the former example, only a, b, c are captured, the unused variables d, ..., x, y, z are not.