C++ Lambdas: capture list vs. parameter list

For example using stl algorithms:

std::vector<int> items;
int factor;
auto foundItem = std::find_if(items.begin(), items.end(), 
[&factor](int const& a) 
{ 
   return a * factor == 100; 
});

In this case you’re called in the lambda for every item in the container and you return if the value multiplied by a captured factor is 100.
The code doesn’t make much sense, it’s just to show you an example where capture and parameter lists matter.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)