template specialization question

Ali Çehreli acehreli at yahoo.com
Mon Feb 1 17:29:00 PST 2010


daoryn wrote:
 > 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)

Regardless of the intent of the document, which may very well be 
outdated or wrong at this time; the specialization above is confusing.

If (T:T[]) is supposed to mean "array type", then the function parameter 
'T[] things' above would mean "array of array". i.e. If T is T[], then 
the parameter is T[][]...

For that reason this is more logical to me, and I would expect it to be 
sufficient to express the specialization:

void print(T:T[])(T things)

But it still selects the general definition above...

I don't know... :)

Ali


More information about the Digitalmars-d-learn mailing list