I'm proposing creating a new tag, constant-expression, and then making constexpr a synonym for constant-expression, rather than constants. Constant expression in C++ requires different usage of language and standard library, thus I believe it deserves a separate tag.
C++11 has added a new keyword,
constexpr. Although it was added later, C++98 already had constant expressions, albeit of extremely limited form. The keyword itself is just a specifier without constant expression.
How is it different from constants or just no tag at all?
I'll take one extreme here (and the lower one, if I'll be able to find it). Compile-time sieve of Eratosthenes. There is no template-metaprogramming involved, but constant-expression would fit in nicely instead of it.
- no tag
A typical review would propose
std::vector and adjustable index. The accepted answer shows the distinction in usage very well:
std::index_sequence instead of index. In fact, the question would get downvoted or receive no votes at all, because people dislike macros in general.
I believe it would fit if primes would be copy-pasted. The primes are not present in the code, but the computation itself is constant-expression. Some constants are constant-expressions (like
const int size = 10), but most of them are not. I believe the tag overall fits for computation of well known numbers Euler's number, pi, and others. Primes might fall into that category, but then both constants and constant-expression should be put.
Most of the non-closed questions clearly imply constant-expression, not
constants. This question looks like more preprocessor metaprogramming, than constants.
New tag wiki
A constant expression is a specific form of an expression, which is currently only available in C++. Use the tag when
constexpr or other form of compile-time expression is implied in the question. The expressions are computed at compile-time, thus they're usable in contexts including, but not limited to
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
I created new tag, constant-expression and populated the wiki. I wanted to create compile-time-function-evaluation, but since I didn't have any general info about it, I decided to postpone it. I also think that @Gareth's idea is good, so the new synonym should be c++-constexpr, which is an alias for constant-expression
const-specified object it just means that it has to be initialized before its first usage (which might actually happen during runtime just before the first usage, see dynamic initialization), which directly contradicts the statement as they cannot be constant-expressions (whose value would be fixed at compile time). Do you mean literals instead? \$\endgroup\$