Partial Specialization using Static If

Xinok xnknet at gmail.com
Sun Dec 24 21:26:04 PST 2006


Going back to my 'multiple specialization' idea...

Static if can pretty much do the job of multiple specialization, except for
one case: partial specialization.

template temp(T : T*)

This doesn't work in a static if:
static if(is(T == T*))
Assuming T = int, the compiler would read this as:
static if(is(int == int*))


I'll forget about the multiple specialization idea for now. We need a simple
way to do partial specialization in a static if expression. It is possible to
do using a specialized template, but it's a bit of work.

template IsPtr(T){
	const bool IsPtr = false;
}
template IsPtr(T : T*){
	const bool IsPtr = true;
}

template temp(T1, T2, T3){
	static if(IsPtr!(T1) || IsPtr!(T2) || IsPtr(T3)){
	}
}



More information about the Digitalmars-d mailing list