alias parameters and basic types

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 30 12:21:27 PDT 2016


On Saturday, July 30, 2016 18:53:43 Lodovico Giaretta via Digitalmars-d wrote:
> Hi,
>
> I know this has been discussed before (like, before I started
> using D on a daily basis and hanging around in the forums), but...
>
> Is there a reason why alias parameters do not accept basic types?
> Will this be changed somewhere in the future, as many asked for
> it? It is very surprising the first time it doesn't work and you
> are forced to add overloads...
>
> Thank you for your answers.
>
> Some quick links:
> https://issues.dlang.org/show_bug.cgi?id=1100
> https://issues.dlang.org/show_bug.cgi?id=3116
> https://issues.dlang.org/show_bug.cgi?id=4639
> https://issues.dlang.org/show_bug.cgi?id=8491
> https://issues.dlang.org/show_bug.cgi?id=9029

I think that Walter's answer in those bug reports is pretty clear. An alias
parameter aliases a symbol. Basic types are keywords, not symbols, so they
can't be passed as an argument to an alias parameter.

And I confess that I don't know why you'd even want to. If you're looking to
pass a type, then just don't use an alias parameter. A normal template
parameter will do just fine. The only reason that I see that makes the
current behavior a bit odd is the fact that other kinds of aliases do work
with types. So, it's arguably inconsistent to not have alias parameters
accept types, but given what alias parameters are intended for and that
they're completely unnecessary for passing types, I don't really see a
problem with the current behavior.

In any case, glancing through those bugs, it's quite clear that the behavior
is intentional what the reasoning is.

- Jonathan M Davis



More information about the Digitalmars-d mailing list