foreach with enum
Ameer Armaly
ameer_armaly at hotmail.com
Thu Jul 19 17:37:24 PDT 2007
"BCS" <ao at pathlink.com> wrote in message
news:ce0a3343bffb8c99827432b23b4 at news.digitalmars.com...
> Reply to Vladimir,
>
>> On Thu, 19 Jul 2007 23:14:59 +0300, Thomas Mader <thezema at gmail.com>
>> wrote:
>>
>>> 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.
>>>
>> for (Color color=Color.min; color<=Color.max; color++)
>> writefln(color);
>
> enum Color { Kreuz = 1, Pik = 2, Herz = 4, Karo = 8 }
>
Maybe make enums work with the in operator? I.E:
enum Color { Kreuz = 1, Pik = 2, Herz = 4, Karo = 8 }
for(int i = Color.min; i <= Color.max; ++i)
{
if( i in Color)
writefln(i);
}
>
More information about the Digitalmars-d
mailing list