Question

Does D provide some way of reflecting on the values of an enumeration, say e, typically iterating over each of its values a bit similar to .tupleof for structs and classes. I guess we could always do

foreach (val; e.min..e.max)

but what about non-continuous enumerations? And enumerations are inclusive on max-value but ranges are not.

Update: I just discovered: http://dlang.org/phobos/std_traits.html#.EnumMembers

I believe this all we need right?

Was it helpful?

Solution

std.traits.EnumMembers can do it, and so can __traits(allMembers,YourEnum).

foreach(value, name; EnumMembers!YourEnum) { } sounds like what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top