Enum to string array

bearophile bearophileHUGS at lycos.com
Wed Oct 1 05:19:45 PDT 2008


Spacen Jasset:
> enum Symbols {
> 		CYCLIC_FORWARD, CYCLIC_BACKWARD, CYCLIC_LEFT, etc
> };
> How could I map this into an array? (or vice-versa) must I use a switch 
> statement, or an enum -> string mapping array?

You can create a template mixin that given the list of names as strings, defines an enum and its array of strings, to map index => symbol. You can also add the opposite mapping, letting it create a switch at compile time, or an associative array, or (but this is often overkill) a perfect hash.

If you need help ask more :-)

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list