Lambda Expressions Capture Mutable Generic
Write lambdas with captures, mutable semantics, and generic auto parameters.
What is a Lambda?
A lambda is an inline anonymous function object. Use it where you would otherwise write a tiny named function or a struct with operator().
auto square = [](int x) { return x * x; };
std::cout << square(5); // 25Syntax Anatomy
A lambda has four parts:
[capture]— what variables from the surrounding scope to use(parameters)— like a function parameter list-> return_type— optional, often deduced{ body }
All lessons in this course
- auto decltype and Type Deduction
- Range-based for nullptr and enum class
- Lambda Expressions Capture Mutable Generic
- Structured Bindings and if-init C++17