www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Template specialization

reply Li Jie <cpunion gmail.com> writes:
I don't know what is the name of this usage:

template <class T> class SomeClass{};
template <class T, class U> class SomeClass< AnotherClass<T,U> >{};

I think this is very commonly used, but D hasn't supported it yet, Is it in the
plain?

- Li Jie
Apr 18 2006
parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
Li Jie wrote:
 I don't know what is the name of this usage:
 
 template <class T> class SomeClass{};
 template <class T, class U> class SomeClass< AnotherClass<T,U> >{};
 
 I think this is very commonly used, but D hasn't supported it yet, Is it in the
 plain?
 
 - Li Jie
 
 

Are you sure? I just tried, and the following works: class SomeClass(T) { T x; } template AnotherClass(T,U) { class AnotherClass( SomeClass(T) ) { } } void main() { }
Apr 18 2006
parent Li Jie <cpunion gmail.com> writes:
In article <e24ltq$2g7f$1 digitaldaemon.com>, Hasan Aljudy says...
Li Jie wrote:
 I don't know what is the name of this usage:
 
 template <class T> class SomeClass{};
 template <class T, class U> class SomeClass< AnotherClass<T,U> >{};
 
 I think this is very commonly used, but D hasn't supported it yet, Is it in the
 plain?
 
 - Li Jie
 
 

Are you sure? I just tried, and the following works: class SomeClass(T) { T x; } template AnotherClass(T,U) { class AnotherClass( SomeClass(T) ) { } } void main() { }

Oh. It's different. // c++ version: # template <class T> # class SomeClass { # public: typedef int some_type; # }; # # template <class T, class U> # class SomeClass< map<T,U> > { # public: typedef short some_type; # }; # # template <class T> # class SomeClass< map<int, T> > { # public: typedef char some_type; # } # # int main() { # SomeClass<int>::some_type a; // int type # SomeClass< map<short, int> >::some_type b; // short type # SomeClass< map<int,short> >::some_type c; // char type # return 0; # } That looks like "implicit template parameters type deduce" + "template specialization". How to do it in D? static if?
Apr 19 2006