It defines a Lambda expression, which is basically a function without a name. It has parameter list (int x, const std::vector<int>&vect)
and a function body { ... }
. But it also has a capture list in the beginning [&]
. If you want to access a variable (which is not a parameter) from the body of the lambda expression, you have to make the expression "take the variable with itself", so that the variable can be used later when the lambda expression will be executed.
You can either provide a list of variables, or use "all" to capture all of them. [&]
means capturing all of them by reference, and [=]
would mean to capture all of them by value.
(If you use [&]
, note that the lambda body will use the value of the variable at the time the lambda is executed, and not the value which was valid when you created the lambda! This is because you do not have a copy of the value, only a reference to it.)