static if - is the 'static' really needed?

comco void.unsigned at gmail.com
Fri Dec 13 04:10:00 PST 2013


Imagine a world in which a simple 'if' has the semantics of a 
static if, if the condition is evaluable at CT. Is this a world 
you would rather live in?

template Fac(int i) {
if (i == 0) { // static if; doesn't introduce scope
enum Fac = 1;
} else {
enum Fac = i * Fac!(i-1);
}
}

// If the condition is not evaluable at CT, the ordinary runtime 
if semantics (introducing scope) are used.

Me:
pros: simpler syntax
cons: harder to reason about; I recall Andrei's talk about the 
static if proposal to C++: "we don't need _static else_" -- why 
do we even need 'static' in 'static if' by this reasoning?


More information about the Digitalmars-d-learn mailing list