Enum literals, good? bad? what do you think?
Walter Bright
newshound2 at digitalmars.com
Wed Jul 21 20:50:30 UTC 2021
On 7/21/2021 12:12 AM, Mike Parker wrote:
> enum expandEnum(EnumType, string fqnEnumType = EnumType.stringof) = (){
> string expandEnum = "enum {";
> foreach(m;__traits(allMembers, EnumType)) {
> expandEnum ~= m ~ " = " ~ fqnEnumType ~ "." ~ m ~ ",";
> }
> expandEnum ~= "}";
> return expandEnum;
> }();
>
> enum MyEnum { blah, bleh, bluh }
> mixin(expandEnum!MyEnum);
>
> auto e = blah;
You & Patrick are da men!
This would make a nice bite-sized article showing off D's metaprogramming
facilities.
More information about the Digitalmars-d
mailing list