foreach with enum
Kirk McDonald
kirklin.mcdonald at gmail.com
Thu Jul 19 14:29:46 PDT 2007
BCS wrote:
> 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)
>
>
No need. You can iterate over tuples directly.
--
Kirk McDonald
http://kirkmcdonald.blogspot.com
Pyd: Connecting D and Python
http://pyd.dsource.org
More information about the Digitalmars-d
mailing list