Alias parameters for templates does not accept built-in types

Michal Minich michal.minich at gmail.com
Sat Aug 14 09:36:28 PDT 2010


On Sat, 14 Aug 2010 04:03:15 +0000, Deokjae Lee wrote:

> template T(alias X) {

> Error: template instance T!(int) does not match template declaration T
> (alias X)

> However, I got a reply that the behavior is intended. I think the
> limitation that the built-in types are not accepted as alias parameters
> for templates is not beautiful :( That's a kind of lack of symmetry and
> practice :) I'd like to know the reason of such a limitation.

I would guess that it is because name of built-in types are keywords, 
while other names are not. But it is possible to overload templates with 
and without alias:

template T(alias X) {
    pragma(msg, "alias X ->"~ X.stringof);
}
template T(X) {
    pragma(msg, "X ->" ~ X.stringof);
}

...given the ability to send keyword aliases to template, templates would 
come closer to macros.


More information about the Digitalmars-d mailing list