I am learning about Lambda Expressions in C++ although I am not a newcomer to C/C++. I am having difficulty seeing the relative merits of using the Capture-Clause vs old fashioned parameter passing in the Argument-List to draw variables into the Lambda body for manipulation. I am familiar with their syntactical differences and what is and is not allowed in each, but just don't see how one is more effective than the other?
If you have insider knowledge, or a better picture of what's going on with Lambdas please let me know.
Many Thanks, Reza.
The difference is that the same capture can be used with different arguments.
Consider the following simple example
The program output is
the arguments for the lambda are supplied by the algorithm std::transform. The algorithm is unable to pass to the lambda the multiplier N. So you need to capture it and the multiplier will be used with any argument passed to the lambda.