Since you cannot throw, you can do something that is illegal in a constexpr environment.
For example, if your condition is that prescalerBits != 0
, you can do:
if (prescalerBits == 0)
*(int*)nullptr = 0;
Which should stop any compile time evaluation. If you are worried about calling this function at runtime and getting a null pointer dereference, you can guard this condition with std::is_constant_evaluated()
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…