[things-to-capture](params) -> return-type { function-body; }
[&foo]...
[foo]...
You can also capture "everything" using [&] or [=]. Handy if you don't want to make an explicit list of captured variables. You can also mix it:
[&foo, bar]...
https://en.cppreference.com/w/cpp/language/lambda
[0] Additionally, lambdas may not have a return value. Like this one:
int n = 0; auto counter = [&n] () { n++; } counter(); // now n == 1
You can also capture "everything" using [&] or [=]. Handy if you don't want to make an explicit list of captured variables. You can also mix it:
Captures foo by reference and a copy of bar.https://en.cppreference.com/w/cpp/language/lambda
[0] Additionally, lambdas may not have a return value. Like this one: