foreach with enum
renoX
renosky at free.fr
Mon Jul 23 15:16:44 PDT 2007
Thomas Mader a écrit :
> I am just porting some of my little Java programs to D to get
> comfortable with the langugage and realized that I cannot use foreach
> with Enums. In Java I can do: enum Color { Kreuz, Pik, Herz, Karo }
> for(Color color : Color.values()) {}
>
> AFAIK thats not possible in D yet.
enum are woefully underpowered in D, you cannot print them correctly,
cannot iterate over them,.. It's a pity because I think that it's a very
important structure (well less than array literals, but still important).
I was inspired by Robert to make also a templated enum version to print
them, (and I'm probably not the only one) but it's a hack..
With macros, hopefully these hacks could become 'less ugly' enough that
we could integrate them in a library..
Regards,
renoX
More information about the Digitalmars-d
mailing list