In C++, we could specify how and what we want to capture from the scope outside the lambda scope in lambda expression. A typical lambda expression will be like follow:
[](const string& a){return a < s;};
There are three level of capture level for lambda expression: []
specify to capture nothing, [&]
specify to capture all variable inside the expression by reference and [=]
specify to capture all variable inside the expression by value.
We could also indicate that what variable should we capture only with the syntax [&x]
or something similar.