Take std::numeric_limits<T>::max()
: for whatever reason, this is a method. constexpr
would be beneficial here.
Another example: you want to declare a C-array (or a std::array
) that is as big as another array. The way to do this at the moment is like so:
int x[10];
int y[sizeof x / sizeof x[0]];
But wouldn’t it be better to be able to write:
int y[size_of(x)];
Thanks to constexpr
, you can:
template <typename T, size_t N>
constexpr size_t size_of(T (&)[N]) {
return N;
}