class template specialization and inheritance
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Fri Jun 13 14:31:05 PDT 2008
mki wrote:
> Bill Baxter Wrote:
>
>>> 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?
>
> Thanks for your answer, Bill.
> I am quite new to D, and it seems that I got this quite wrong.
> I believed that for a template to be a specialization of another, the number of template parameters must be the same.
>
> With this new insight the code of my original problem changes to
>
> //begin code example
> import std.stdio;
>
> class A(T) { }
>
> class B(T) : A!(T) { }
>
> class C(T) {
> static void tellMe() {
> writefln("generic.");
> }
> }
>
> class C(TT:A!(T),T) {
> static void tellMe() {
> writefln("TT is the same as or derived from A!(T).");
> }
> }
>
> void main() {
> C!(A!(int)).tellMe();
> C!(B!(int)).tellMe();
> C!(int).tellMe();
> }
> //end code example
>
> which still gives (using DMD 2.008)
>
> T is the same as or derived from A!(TT).
> generic.
> generic.
>
> where the second line should be "T is the same as or derived from A!(TT)." in my opinion.
> Am I still doing something wrong, or is this a bug?
>
>> Sadly the argument deduction (IFTI) implementation is not very complete.
>> It only works in very specific situations.
>
> Thats bad.
> I'm writing heavily templated generic code, currently in C++ with its sometimes very painful template syntax. I hoped that I could switch to D.
>
> But an incomplete argument deduction implementation is worse than the C++ template syntax.
>
> ~mki
Seem my comments to your bug report. I don't think it's a bug, but
rather an enhancement request, but it's hard to say for sure since (IMO)
the spec is somewhat murky on matters of template specialization.
There is a workaround there which should work for what you want, unless
you have some other requisite you didn't mention.
--
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d
mailing list