class template specialization and inheritance
Bill Baxter
dnewsgroup at billbaxter.com
Wed May 14 21:30:02 PDT 2008
Edward Diener wrote:
> 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.
Yeh, my C++ is a bit rusty from too much D. :-)
> 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.
Right, I was just pointing out what I thought might have been the
original poster's intention.
--bb
More information about the Digitalmars-d
mailing list