class template specialization and inheritance

Edward Diener eddielee_no_spam_here at tropicsoft.com
Wed May 14 19:46:32 PDT 2008


Bill Baxter wrote:
> Edward Diener wrote:
>> mki wrote:
>>> Hello!
>>>
>>> I just discovered the template syntax of D. I am very exited about 
>>> its simplicity compared to C++.
>>>
>>> Now I ran into a template behavior I do not understand. This code:
>>  > snip...
>>> class C(TT:A!(T)) {
>>>     static void tellMe() {
>>>         writefln("derived from A!(T).");
>>>     }
>>> }
>>
>> Huh ! What is T above ? I do not think that your use of T should be 
>> legal. Are you sure you did not mean 'class C(TT:A!(TT)) { etc.' ?
> 
> I think it's supposed to be legal using:
> 
> class C(TT:A!(T), T)

This makes sense since T is another template parameter. In the original, 
quoted further above, there was no second template parameter of T, which 
should generate a compiler error.

> 
> That is, one template parameter can depend on another in a non-trivial 
> way in theory. But I think the compiler has trouble with such things 
> right now.
> 
>  From what I understand that is the intended way to do C++ things like 
> this in D:
> 
> template <typename Z>
> template class C { ... }
> 
> // specialization for all Z == A<T> for template A and some T
> template <typename T>
>   template class C< A<T> > { ... }

If this is meant as C++ the second use of 'template' each time is 
incorrect. Otherwise it is correct partial specialization syntax as you 
mention. But notice that T is a template parameter in your C++ 
equivalent example while in the OP's original which I cited as 
erroneous, there is no T as a template parameter.



More information about the Digitalmars-d mailing list