On 02/01/2010 07:29 PM, Ali Çehreli wrote:
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.
It is.
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[][]...
I wondered that too.
I think what happens is the type is matched to T[], and not T, and then
it figures out from there what T should be, so that T[] in the function
parameter is the same as the type passed in.
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