Template function specialization doesn't work

IGotD- nise at nise.com
Tue Jul 7 19:53:30 UTC 2020


I have two template functions

void overloadedFunction(T)(ref T val)
{
...
}
	
	
void overloadedFunction(T : T[])(ref T[] s)
{
...
}

Obviously the second should be used when the parameter is a slice 
of any type, and the first should be used in other cases. However 
this doesn't happen, the compiler always picks the first function 
regardless if the parameter is a slice or not.

So

ubyte[3] ar = [ 1, 2, 3 ];
ubyte[] arSlice = ar;

overloadedFunction(arSlice);

The first function will be used. Shouldn't the template argument 
(T : T[]) make the compiler pick the second one?



More information about the Digitalmars-d-learn mailing list