Quantcast
Channel: User Peter - Reinstate Monica - Stack Overflow
Viewing all articles
Browse latest Browse all 239

Comment by Peter - Reinstate Monica on Difference between "if constexpr()" Vs "if()"

$
0
0
@ReinstateMonica3167040 Well, this states the rules but not the reason: The compiler "knows" perfectly well which branch will be executed, constexpr or not, and could hence compile it perfectly identically with or without it. I can think of only two reasons constexpr was introduced: 1. Errors in the branch not taken are in some cases intentional to prevent compilation (e.g. for certain template type arguments). Changing the language and demanding that the not-taken branch was not compiled would break backwards compatibility. 2. Flag cases that are actually not compile-time decidable.

Viewing all articles
Browse latest Browse all 239

Trending Articles