Comparison chart of D and C++ templates

Walter Bright newshound at digitalmars.com
Fri Jan 19 03:06:35 PST 2007


Kazuhiro Inaba wrote:
>>                          D  C++98 C++0x
>> Partial Specialization | Yes  Yes  NoChange
> 
> Actually, partial specialization in D is a kind of yes-and-no.
> In C++98, we can do this:
>   template<class T, class U>
>     class Foo< map<T,U> > { ... }; // Partially specialized to "associative arrays"
> while in D, cannot:
>   class Foo(T: /* ? */) {}

You're right there is a problem when one wants to specialize on a type
dependent on more than one parameter.
You can do things like:

    class Foo(T, U, M : map!(T,U)) ...

but it isn't quite as clean.

> Combination of staticIf/typeof/IFTI may achieve the same effect,
> but in my opinion it is not partial specialization anymore.

static if can do a reasonable job covering for it.



More information about the Digitalmars-d-announce mailing list