iterate over enum name:value pairs

bearophile bearophileHUGS at lycos.com
Sun Dec 8 03:05:23 PST 2013


Jay Norwood:

>     enum Suit { spades, hearts=4, diamonds=10, clubs }
>
>     foreach (i, member; EnumMembers!Suit)

Here 'i' is the index of the enumeration type tuple.

This code lacks the [] I added in my code, so your foreach is a 
static one. To tell them apart when I read the code I sometimes 
add a comment:

/*static*/ foreach (i, member; EnumMembers!Suit)

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list