class template specialization and inheritance
Bill Baxter
dnewsgroup at billbaxter.com
Sun May 18 14:04:24 PDT 2008
mki wrote:
> 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.
From http://www.digitalmars.com/d/1.0/template.html
"""
Deduction from a specialization can provide values for more than one
parameter:
template Foo(T: T[U], U)
{
...
}
Foo!(int[long]) // instantiates Foo with T set to int, U set to long
"""
But (for D1 at least) that doesn't work with argument deduction:
void fBaz(T: T[U], U)(T[U] x) {
writefln("typeof(T)=",typeid(T)," typeof(U)=",typeid(U));
}
...
int[long] z;
fBaz(z);
>> partialifti.d(24): template partialifti.fBaz(T : T[U],U)
specialization not allowed for deduced parameter T
> 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_.
According to the documentation D thinks it is. Do you have evidence to
the contrary?
> 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?
Sadly the argument deduction (IFTI) implementation is not very complete.
It only works in very specific situations.
--bb
More information about the Digitalmars-d
mailing list