Enum to string array

Spacen Jasset spacenjasset at yahoo.co.uk
Wed Oct 1 09:04:10 PDT 2008


Don wrote:
> 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.
> 
> Such a thing already exists in phobos2 in std.typecons.
I will have a look at how this works. Presumably is DMD2, which I don't 
currently use.


More information about the Digitalmars-d-learn mailing list