How to iterate string enum values?

IchorDev zxinsworld at gmail.com
Sat Dec 28 12:27:21 UTC 2024


On Monday, 23 December 2024 at 20:32:58 UTC, Anton Pastukhov 
wrote:
> On Monday, 23 December 2024 at 20:26:47 UTC, bauss wrote:
>
>> Simply cast el to a string instead of using std.conv.to
>
> Thanks much, it worked! Though I'm confused why. Could you 
> please elaborate?

Well, `to!string` gets a *string representation* of a value. For 
an enum, that's its member name. `cast(string)` just converts the 
enum value to its base type. Practically speaking, you can 
probably just use `[EnumMembers!BodyType]`, since `BodyType` will 
implicitly convert to its base-type of `string` anyway.


More information about the Digitalmars-d-learn mailing list