template specialization question

daoryn manse at fots.po
Sun Jan 31 10:49:44 PST 2010


According to http://digitalmars.com/d/2.0/template.html it is possible to specify template specialization so that DMD prefers them when instanciating templates, however the following code:


---------------------------------
import std.stdio;

void print(T)(T thing)
{
	writeln("Calling print(T)");
	writeln(T.stringof);
}

void print(T:T[])(T[] things)
{
	writeln("Calling print(T[])");
	writeln(T.stringof);
}

void main()
{
	print(3);
	print([1,2,3]);
}

-----------------------------------------

will output:

Calling print(T)
int
Calling print(T)
int[3u]

I expected it to output "calling print(T[])" on the second "print". Would this be a bug or did I misunderstand the template specialization?



More information about the Digitalmars-d-learn mailing list