Enum to string array

Spacen Jasset spacenjasset at yahoo.co.uk
Wed Oct 1 08:50:43 PDT 2008


bearophile wrote:
> 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

This sounds interesting. Can you give me a simple example of this. I 
don't really deal in mixins and templates much at the moment, so I 
cannot imagine how this might be done.


More information about the Digitalmars-d-learn mailing list