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?

有帮助吗?

解决方案

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

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top