Not getting expected behavior from compile-time conditional
pineapple via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jan 26 16:12:15 PST 2016
Here's a simple programming showing where I'm tripping up -
void test(T)(in T value){
import std.traits;
static if(is(T == char)){
writeln("char");
}else static if(is(isNumeric!(T))){
writeln("number");
}
writeln("hi");
}
public void main(){
test('g');
test(2);
test(2.0);
}
Output is this -
char
hi
hi
hi
I was expecting output to look like this -
char
hi
number
hi
number
hi
How can I fix this?
More information about the Digitalmars-d-learn
mailing list