D's limited template specialization abilities compared to C++

Ahuzhgairl bulletproofchest at gmail.com
Sat May 25 03:46:03 PDT 2013


Hi,

In D, the : in a template parameter list only binds to 1 
parameter.
There is no way to specialize upon the entire template parameter 
list.
Therefore you can't do much with the pattern matching and it's 
not powerful.
Not a reasonable situation for a language aiming to be only the 
best.

What is needed is the ability to bind to the whole template 
parameter list:

template <class> struct get_class;
template <class R, class C, class... A> struct get_class<R 
(C::*)(A...)> { typedef C type; };

Let's shorten the terms:

<R, C, A...> @ <R (C::*)(A...)>

And here's how this kind of specialization would work in D:

template A[B] { struct C {} } template Foo[alias X, Y, Z @ 
X[Y].Z] { alias Z Foo; } void main() { alias Foo[A[bool].C] xxx; }

You need a separate delimiter besides : which does not bind to 
individual parameters, but which binds to the set of parameters.

I propose @ as the character which shall be the delimiter for the 
arguments to the pattern match, and the pattern match.

On an unrelated note, I don't like the ! thing so I use []. Sorry 
for the confusion there.

z


More information about the Digitalmars-d mailing list