Iterating through enumeration

bearophile bearophileHUGS at lycos.com
Sun Aug 12 04:54:51 PDT 2012


Era Scarecrow:

>  But that problem goes away if you turn it into a small array 
> right? (And pass the array to the foreach to cycle over) So 
> throwing that idea out there you get...
>
> foo[] array;
>
> foreach(m; std.traits.EnumMembers!foo)
>     array ~= m;
>
> foreach(m; array) {
>  //not compiler-time expansion like above
> }

Often better (but every time builds an array on the heap):

foreach (m; [EnumMembers!Foo]) { // Not a static foreach
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list