constexpr Lambda Functions

Lambda functions are now compatible with constant expressions.

Lambda expressions were introduced in C++11, and since that moment they’ve become an essential part of modern C++. Another significant feature of C++11 is the constexpr specifier, which is used to express that a function or value can be computed at compile-time.

In C++17, the two elements are allowed to exist together, so your lambda can be invoked in a constant expression context.

In C++11/14 the following code doesn’t compile, but works with C++17:

Get hands-on with 1200+ tech skills courses.