
On Sun, Aug 31, 2014 at 10:09 PM, Robert Ramey
pfultz2 wrote
since the condition is known at compile time, can't the optimizer be counted on to compile only the corresponding code? Why doesn't this give the same effect as the proposal?
Both branches still have to compile even if the compiler determines it is dead code.
Paul
So what, the final executables would be equivalent if not identical.
If both branches are able to compile, then yes, probably. The problem is that when you use this kind of branching, it's often the case that when the condition is false, the true branch would have a compilation failure (or vice versa). Regardless of which branch is taken, even when the condition is a compile-time constant, both branches need to be compiled and any templates involved need to be instantiated, so using a regular if either could fail compilation or greatly increase compile-times, neither of which is desirable. -- -Matt Calabrese