Lambdas solve a problem of readability, expressiveness and practicality. In this article we’ll show you 10 ways you can use it in your code.
Syntax
Example 1
This doesn’t do anything, but it’s the most basic way to compile without error.
Example 2
Assigning Lambda Return to a Variable
Example 3
Inserting content into the body of the lambada
Example 4
Printing the contents of the lambda
Example 5
Passing parameter to Lambda
Example 6
Returning defined type
Example 7
Passing existing variables
Example 8
Running inside std::remove_if
and leaving the NUM(123.456.789-00) with only numbers
To see the output: for( auto z : num ){ std::cout << z; }; std::cout << '\n';
Example 9
Calling with direct parameters
Example 10
Capturing the clause as a reference
That’s all for today, small daily doses that will always keep us in tune with C++!
cpp
cppdaily
Marcos Oliveira
Software developer