Template specialization rules and alias parameters.

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Sun Apr 9 06:32:31 PDT 2006


Both in the D doc, and in
www.digitalmars.com/d/templates-revisited.html
the rules about template specialization are omissive about alias 
parameters. I think a clarification is important, even more because the 
actual behavior seems a bit strange to me. See the code below.


class Foo { }	
	
class FooBar : Foo {}

template Xpto(T:FooBar) {
   int a = 1;
}

template Xpto(alias T) {
   int a = 2;
}

template Xpto(T:Foo) {
   int a = 3;
}

template Xpto(T) {
   int a = 4;
}

int main(char[][] args)
{
   writefln( Xpto!(FooBar).a );
}


The templates are shown ordered according to the order of preference in 
which they are chosen to specialize the Xpto!(FooBar) instance. As you 
can see the alias parameter is in the middle of the preference order, 
which seems strange to me. Shouldn't it be the first, or the last? (the 
last more likely, since it is less specific than a type parameter)

-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d-announce mailing list