Constexpr lambdas
Since C++11 we are able to use the constexpr specifier which evaluates the expression at compile time, with C++17 lambdas can also be constant expressions. One use case could be to initialize constexpr variables that depend on other constexpr variables. See the following example:
This example maybe is silly but imagine a much more complex dependency and the array consists of more complex elements than simple integers.
Compiler Support
These features are all fully supported by GCC, MSVC, and clang. Below follows a table showing which version enables support for each feature respectively.
For more a detailed matrix with more compilers and all features of C++17 listed, follow this link.
Endnote
This was the last part of the series “6 Useful New Features in C++17” and I hope you found it helpful and interesting. All the previous blog posts in this series you will find under “NEWS“.
Don’t hesitate to share with your friends and colleagues and stay tuned for more!
//Patrik Ingmarsson, Software Developer