Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC++constexpr consteval constinitSingle-choice MCQ

Inside a `constexpr` function, `std::is_constant_evaluated()` is used to branch between a compile-time and runtime implementation. Why is writing `if constexpr (std::is_constant_evaluated())` a classic bug rather than the intended pattern?

constexpr int pick(int x) { if constexpr (std::is_constant_evaluated()) return x + 1; // always taken else return x - 1; }