class template specialization and inheritance
mki
none at none.com
Sun May 18 06:11:51 PDT 2008
Thanks for your answers!
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.
I don't see why the original
class C(TT:A!(T))
shouldn't be legal.
in C++ style syntax I would have
//primary template
template<typename T>
class C {};
//template specialization of C
template<typename TT, typename T>
class C<TT:A<T> > ... ;
(Of course this isn't legal either, because C++ doesn't have the colon-syntax.)
Now D does away with primary templates, so the first part can be skipped completely in D.
Furthermore, D does not need the line
template<typename TT, typename T>
because the template parameters of the specialization can be completely deduced from the expression C<TT:A<T> >. All undeclared symbols are template parameters.
So to my understanding,
C(TT:A(T))
should be legal D and should have the sense I indicated with the C++ style syntax above. Also notice that there is no compiler error message on this expression.
For my programming purpose, the important thing is that C(TT:A(T)) is a specialization of C(T), but the suggested C(TT:A(T),T) is _not_.
For this reason, I really need the first variant, and not the second one.
I would like to hear further opinions on this. I my understanding correct, or not?
More information about the Digitalmars-d
mailing list