Enum literals, good? bad? what do you think?
Patrick Schluter
Patrick.Schluter at bbox.fr
Wed Jul 21 07:11:00 UTC 2021
On Wednesday, 21 July 2021 at 06:39:18 UTC, Walter Bright wrote:
[...]
> But if you still want unqualified names, `alias` is the feature:
>
>
> enum MyEnum { blah, bleh, bluh }
> alias blah = MyEnum.blah;
> alias bleh = MyEnum.bleh;
> alias bluh = MyEnum.bluh;
>
> `alias` is an all-purpose tool for moving names from one scope
> to another. Of course, one can probably do a mixin to automate
> the alias declarations. It should be a fun exercise. Any takers?
mixin({
auto aliasList = "";
static foreach(m; __traits(allMembers, MyEnum))
aliasList ~= "alias "~m~" = MyEnum."~m~";\n"
return aliasList;
}());
>
> (As mentioned by others, `with` does it too, but `with` only
> affects the scope it specifies.)
More information about the Digitalmars-d
mailing list