Since the extended versions of constexpr (I think from C++14) you can declare constexpr functions that could be used as "real" cons
C++20 introduces is_constant_evaluated, defined in header , which addresses this issue.
constexpr int foo(int s)
{
if (std::is_constant_evaluated()) // note: not "if constexpr"
/* evaluated at compile time */;
else
/* evaluated at run time */;
}
Note that here the ordinary if is used instead of if constexpr. If you use if constexpr, then the condition has to be evaluated at compile time, so is_constant_evaluated always returns true, rendering the test useless.