foreach with enum

BCS ao at pathlink.com
Thu Jul 19 13:29:47 PDT 2007


Reply to Thomas,

> 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.
> 

I think you are out of luck. Really enums should have a .tupleof propriety. 
Then this would work:

foreach(A a; [A.tupleof]){...}

(if putting a tuple inside an array worked as expected)





More information about the Digitalmars-d mailing list