D's limited template specialization abilities compared to C++
deadalnix
deadalnix at gmail.com
Sat May 25 09:27:57 PDT 2013
On Saturday, 25 May 2013 at 10:46:05 UTC, Ahuzhgairl wrote:
> 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
Hi, I obviously don't know D that much, but I assume I do.
I have this feature that I can't even show a working example that
exists in C++. I also can't come up with any use case, but I know
this is mandatory to have.
As I assume I know D well enough, I assume I know that this is
impossible in D, so I propose an improvement.
With that improvement, a new syntax is introduced to support some
new feature that is barely defined and it can be used in unknown
situation.
I also explain myself using my own made up syntax. I don't care
if it conflict with other language construct as it is superior
anyway.
More information about the Digitalmars-d
mailing list