In our previous Lambda expression examples, we keep the capturing part and the square bracket ([]) empty since the Lambda doesn't capture anything and doesn't have any extra member variable in the anonymous object generated by the compiler. We can also specify the object we want to capture in the Lambda expression by specifying it in this square bracket. Let's take a look at the following piece of code to go through the discussion:
/* lambda_capturing_by_value.cpp */ #include <vector> #include <algorithm> #include <iostream> using namespace std; auto main() -> int { cout << "[lambda_capturing_by_value.cpp]" << endl; // Initializing a vector containing integer element vector<int> vect; for (int i ...