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

Timon Gehr timon.gehr at gmx.ch
Wed Aug 8 02:13:30 PDT 2012


On 08/07/2012 03:52 PM, Philippe Sigaud wrote:
> 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)
> ...

Yes, but note that this distinction does not make any sense.

alias int Int; // works

isType!Int // 'Int' is clearly a symbol, yet the instantiation fails.

alias declarations should just accept built-in types. If someone for
some obscure reason needs to exclude them, template constraints are
good enough. There is no reason to make built-in types behave specially
here.



More information about the Digitalmars-d-learn mailing list