From C++11 on, you can write
lambdas that capture local variables into them, though it does not happen unless you ask for it. That is, if you write the empty capture list
[]
, nothing is captured. If you want to capture everything that your lambda would use, you would have to write
[=]
(to capture by value) or
[&]
(to capture by reference). This is dissimilar to closures in languages like Python and C# where capturing is always automatic.