I'm implementing a constexpr int foo();
function. In the body of foo()
, I want to do something different (and possibly return something different) at compile time and something different at run-time.
With C++20, I can use std::is_constant_evaluated
:
constexpr int foo() { return std::is_constant_evaluated() ? 123 : 456 };
but what if I'm using C++17 (or earlier) - what can I do with the same effect?
Note: Compiler-specific solutions are acceptable (though less desirable).