Why __traits(compile,...) fails here?

Philippe Sigaud philippe.sigaud at gmail.com
Tue Aug 7 06:52:42 PDT 2012


On Tue, Aug 7, 2012 at 12:42 PM, Zhenya <zheny at list.ru> wrote:

>> Template alias parameters do not accept built-in types.

The trick is:

- A template type parameter (like (T)) recognizes types
- A template alias parameter(like (alias a)) recognizes names, symbols.

A built-in type is 'purely' a type. It's a keyword, and hence it's not
a symbol ('int' cannot be a D identifier)
A user-defined type is *both* a type and a symbol (because it has a name)

So, given:

class C {}
template isType(T) { ... }
template isName(alias name) { ... }

then

isType!int => accepted
isType!C => accepted

isName!int => not accepted
isName!C => accepted

which also means you can design a template that accepts

- only built-in types
- only user-defined types
- both
- neither (with other template parameters...)


More information about the Digitalmars-d-learn mailing list