Use this whenever compile-time expression is implemented (currently exists in C++ and D). Do not put this tag if the compile-time evaluation property is achieved through template metaprogramming in C++ (in which case use [tag:template-meta-programming]).

A constant expression is a specific form of an expression, which is available in and . Use the tag when constexpr or other form of compile-time expression is implied in the question. The expressions are computed at compile-time.

C++

They're usable in contexts including, but not limited to

  • switch statement

  • C style array size

  • Template argument (only built-in types as of C++17)

constexpr keyword is often associated with constant-expression. It can be used in two contexts: variables and functions. In case of variables, if the expression is not constant-expression, declaration of the variables will cause compilation error. In usage as a specifier in function declarations, it tells about a function which can potentially be computed at compile time if the arguments are themselves constant-expressions.

Most of the time it is used in tandem with template-metaprogramming. Other common usage is compile-time computations. For more info, please see cppreference page about constant-expressions and constexpr.

history | excerpt history