Lambdas

suggest change

Syntax

Parameters

Parameter | Details | ——— | —–– |default-capture | Specifies how all non-listed variables are captured. Can be = (capture by value) or & (capture by reference). If omitted, non-listed variables are inaccessible within the lambda-body. The default-capture must precede the capture-list. |capture-list | Specifies how local variables are made accessible within the lambda-body. Variables without prefix are captured by value. Variables prefixed with & are captured by reference. Within a class method, this can be used to make all its members accessible by reference. Non-listed variables are inaccessible, unless the list is preceded by a default-capture. |argument-list | Specifies the arguments of the lambda function. | mutable | (optional) Normally variables captured by value are const. Specifying mutable makes them non-const. Changes to those variables are retained between calls.throw-specification | (optional) Specifies the exception throwing behavior of the lambda function. For example: noexcept or throw(std::exception).|attributes | (optional) Any attributes for the lambda function. For example, if the lambda-body always throws an exception then [[noreturn]] can be used. -> return-type | (optional) Specifies the return type of the lambda function. Required when the return type cannot be determined by the compiler. |lambda-body | A code block containing the implementation of the lambda function. |

Remarks

C++17 (the current draft) introduces constexpr lambdas, basically lambdas that can be evaluated at compile time. A lambda is automatically constexpr if it satisfies constexpr requirements, but you can also specify it using the constexpr keyword:

//Explicitly define this lambdas as constexpr
[]() constexpr {
    //Do stuff
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Lambdas:
* Lambdas

Table Of Contents
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype