iterate over enum name:value pairs

Jay Norwood jayn at prismnet.com
Sun Dec 8 20:15:56 PST 2013


I notice that if Suit and SuitShort have an enum with the same 
name, then you still have to fully qualify the enum names when 
using the with statement.  So, for example, if spd in SuitShort 
was renamed spades, the first entry in the array initialization 
would have to be {Suit.spades, 1, 6, SuitShort.spades}.

>>    with (Suit) with (SuitShort)
>>    {
>>        static Suits[] suits = [
>>            {spades,    1,  6, spd},
>>            {hearts,    4, 10, hrt},
>>            {diamonds,  4, 10, dmd},
>>            {clubs,    10, 16, clb}
>>        ];
>>
>>        foreach (immutable member;  suits)
>>        ...
>>
>>
>> Bye,
>> bearophile



More information about the Digitalmars-d-learn mailing list