How to iterate string enum values?

Anton Pastukhov mail at anton9.com
Mon Dec 23 20:20:02 UTC 2024


I'm stuck on a simple problem.
There is this string enum of MIME types:

```d
enum BodyType: string {
     PlainText = "text/plain",
     JSON = "apllication/json",
     FormUrlencoded = "application/x-www-form-urlencoded",
     Multipart = "multipart/form-data",
     Other = "Other",
     None = "None"
}
```

Q: how can I iterate its values? With keys it's relatively easy:

```d
auto keys = [EnumMembers!BodyType]
     .map!(el => to!string(el))
     .array;

```
With values, though, I'm kinda stuck. Reading Ali's book and 
https://dlang.org/spec/enum.html did not bring enlightening


More information about the Digitalmars-d-learn mailing list