constexpr
In this lesson, we'll study constexpr.
Constant Expressions
You can define, with the keyword constexpr, an expression that can be evaluated at compile-time. constexpr can be used for variables, functions, and user-defined types. An expression that is evaluated at compile-time has a lot of advantages.
A constant expression
- can be evaluated at compile-time.
- gives the compiler deep insight into the code.
- is implicitly thread-safe.
constexpr - Variables and Objects
If you declare a variable as constexpr, the compiler will evaluate them at compile-time. ...