template specialization question

Tomek Sowiński just at ask.me
Sun Jan 31 11:59:47 PST 2010


Dnia 31-01-2010 o 19:49:44 daoryn <manse at fots.po> napisał(a):

> 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]);
> }

I'd say it should be more like:

// specialization needed to limit matching types
void print(T:int)(T thing)
{
	writeln("Calling print(T)");
	writeln(T.stringof);
}

// T is an array of any Us.
void print(T:U[], U)(T things)
{
	writeln("Calling print(T[])");
	writeln(T.stringof);
}


Tomek


More information about the Digitalmars-d-learn mailing list