enum scope

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Jan 28 13:36:17 PST 2012


On 1/28/12, Trass3r <un at known.com> wrote:
> The extra template is senseless.

No it's not. Your sample won't compile with -property. That's why I've
wrapped it into a template, to avoid having to use parens.

> And no imports are needed.

Fair enough. But if we're going to be anal about it you should add a
constraint `if (is(EnumType == enum))`. Otherwise your sample will
compile for non-enum types, which may or may not be what you want. You
probably don't want to end up with static method imported into the
local scope by accident. For classes it will generate:

alias MyClass.toString toString;
alias MyClass.toHash toHash;
alias MyClass.opCmp opCmp;
alias MyClass.opEquals opEquals;
alias MyClass.Monitor Monitor;
alias MyClass.factory factory;

Fun! :)


More information about the Digitalmars-d mailing list