class template specialization and inheritance

mki none at none.com
Sun May 18 15:03:57 PDT 2008


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



More information about the Digitalmars-d mailing list