According to the C++11 standard, lambda expressions may use variables in the enclosing scope, by means of the capture list, the parameter list or both.
So, let\'s look
The point is that with capture, you can keep a state (just as a hand written class with operator() ) in a function-like object. @dau_sama gives a good answer. Here is another example:
#include
using namespace std;
int main() {
const auto addSome = [](double some){
return [some](double val){ return some+val; } ;
};
const auto addFive = addSome(5);
std::cout << addFive(2) << std::endl;
}