DIPX: Enum Literals / Implicit Selector Expression
Mike Parker
aldacron at gmail.com
Thu Jun 30 11:22:40 UTC 2022
On Thursday, 30 June 2022 at 11:06:31 UTC, The Zealot wrote:
>
> you can always alias the enums into global scope too, if you
> want to have short names.
>
E.g.,
```D
enum expandEnum(EnumType, string fqnEnumType = EnumType.stringof)
= (){
string expandEnum;
foreach(m;__traits(allMembers, EnumType)) {
expandEnum ~= "alias " ~ m ~ " = " ~ fqnEnumType ~ "." ~
m ~ ";";
}
return expandEnum;
}();
enum Color {
red,
green,
blue,
yellow,
orange,
black,
white,
}
mixin(expandEnum!Color);
void main() {
auto c = green;
writeln(c);
}
```
More information about the Digitalmars-d
mailing list