is expression with static if matches wrong type

tcak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 22 21:35:53 PDT 2015


[code]
import std.stdio;

public void setMarker(M)( size_t markerIndex, M markerValue )
	if(
		is(M: ulong) || is(M: long) ||
		is(M: uint) || is(M: int) ||
		is(M: ushort) || is(M: short) ||
		is(M: ubyte) || is(M: byte) || is(M: char) || is(bool) ||
		is(M: double) ||
		is(M: float)
	)
{
	static if( is(M: ulong) || is(M: long) ){
		std.stdio.writeln("Here 1: ", typeid(M));
	}

	else static if( is(M: uint) || is(M: int) ){
		std.stdio.writeln("Here 2: ", typeid(M));
	}

	else static if( is(M: ushort) || is(M: short) ){
		std.stdio.writeln("Here 3: ", typeid(M));
	}

	else static if( is(M: ubyte) || is(M: byte) || is(M: char) || 
is(bool) ){
		std.stdio.writeln("Here 4: ", typeid(M));
	}
}

void main() {
	setMarker( 0, cast(ubyte)5 );
}

[/code]



Result:
Here 1: ubyte


Compiler and OS:
DMD 2.067.1  on Ubuntu 14.04 64-bit


Expected:
Here 4: ubyte


is(my expectation) wrong?


More information about the Digitalmars-d-learn mailing list