Instantiating template classes with default template arguments
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Fri Feb 16 02:12:03 PST 2007
Sean Kelly wrote:
> Bruno Medeiros wrote:
>> Sean Kelly wrote:
>>>
>>> P.S. In writing this, I discovered that the following code compiles
>>> when it should not:
>>>
>>> class C( T = int, U = int ) {}
>>> class C( T = int, U : char = int ) {}
>>>
>>> void main()
>>> {
>>> auto c = new C!(int);
>>> }
>>
>> What's wrong with that?
>
> Oops... you're right. I edited that from my original example:
>
> class C( T = int, U = int ) {}
> class C( T = int, U : char = char ) {}
>
> void main()
> {
> auto c = new C!(int);
> }
>
> This one shouldn't compile and does. Unless the defaults are always
> chosen from the lexically first match?
>
>
>
> Sean
The template that matches is the char one, the second one. It matches
that one regardless of lexical order. I suspect that's because it is a
specialization, thus having more priority. For instance, the following
fails with an ambiguity error:
class C( T = int, U : int = int ) { pragma(msg,"int");}
class C( T = int, U : char = char ) { pragma(msg,"char"); }
void main()
{
//template instance C!(int) matches more than one template declaration
auto c = new C!(int);
}
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list