Template specialization

Li Jie cpunion at gmail.com
Wed Apr 19 00:53:16 PDT 2006


In article <e24ltq$2g7f$1 at 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?





More information about the Digitalmars-d mailing list