Let's start with the example (godbolt):
constexpr int len(int v) {
if (std::is_constant_evaluated()) {
// static_assert(v > 0); // ERR: 'v' is not a constant expression
return v;
} else {
return 0;
}
}
using A = std::array<int, len(3)>;
The problem is, that the static_assert won't compile (gcc / clang latest 10.x releases). Apparently, v isn't realized to be constexpr when std::is_constant_evaluated returns true. But clearly, by the use of len, it actually is.
Question: Is it possible to use a variable as constexpr if and only if std::is_constant_evaluated? If so, how?