Constant Expressions: constexpr
With the keyword
constexpr, we define 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 many advantages.
A constant expression does the following:
- It can be evaluated at compile time.
- It gives the compiler deep insight into the code.
- It is implicitly thread-safe.
- It can be constructed in the read-only memory (ROM-able).