if constexpr
is not "faster if
". It's not the if
statement you use when a conditional expression happens to be a constant expression. It's not even the if
statement you use when you want the compiler to test the condition at compile time (compilers are capable of doing that on their own).
The meaning of the if constexpr
usage in your second example is that the expression C()
is not meant to be valid C++ unless the condition represented by A
is true. This is why you guard a code block with if constexpr
; this is why the feature was added to the language to begin with. Obviously you can use it for other things, but if all you care about is getting the compiler to evaluate a condition expression at compile-time, you shouldn't be using if constexpr
.
And it is for this reason why what you're asking for is not forthcoming.
Looking at your second example, the difficulties in replicating if constexpr
's behavior across an expression that is only partially a constant expression become apparent. The rules would need a fair bit of complexity. In your example, D()
must be valid C++ code even if A
is true, since B
could be false at runtime.
You'd need to build some fairly complex rules about how such "partial constexpr" expressions prohibit the evaluation of the various code branches. And that can easily lead to difficulty in users understanding when a complex expression will cull out which branches and when it won't.
Better to just make users write it out long-form in these cases.