Enum to string array
Bill Baxter
wbaxter at gmail.com
Wed Oct 1 11:56:47 PDT 2008
On Thu, Oct 2, 2008 at 1:04 AM, Spacen Jasset <spacenjasset at yahoo.co.uk> wrote:
> 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.
It is D2, but there's a port of it to D1 in the "std2" project.
http://www.dsource.org/projects/std2/browser/trunk/std2/std2/typecons.d
It's not one of the modules I've used, though, so I can't recall if it
actually worked or not. (For some reason I didn't put it in the list
of "ported modules" here http://www.dsource.org/projects/std2. --
could be I just forgot to update that list after porting it.)
--bb
More information about the Digitalmars-d-learn
mailing list