Ellery Newcomer:
> Somewhat OT: I wish enums had something analogous to struct's tupleof, 
> or some way to enumerate the values of the enum, and maybe their names 
> too. Do they?

D2 now gives you the tools to do that, even if it's bad looking code:

import std.stdio: writeln;
enum Foo { Aa, Bb, Cc }
void main() {
    foreach (name; __traits(allMembers, Foo))
        writeln(name, " ", mixin("cast(int)Foo." ~ name));
}


Output:
Aa 0
Bb 1
Cc 2

Bye,
bearophile

Reply via email to