www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - string[] enumerations

reply Nrgyzer <nrgyzer gmail.com> writes:
Hi there,

I need enumerations with string[] as base type. It works when I use

enum MyEnum : string[] {
 a = ["a", "b", "c"],
}

but when I add more types like

enum MyEnum : string[] {
 a = ["a", "b", "c"],
 b = ["d", "e", "f"],
 c = ["g", "h", "i"], // ...
}

I always get the following error(s):

Error: Integer constant expression expected instead of ["a", "b",
"c"] < ["a", "b", "c"]

Is there any solution in D to realize to add more than one string[]-
array to an enumeration?

Thanks!
May 10 2011
next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
I've ran into the same problem.

There's a way to partially simulate an enum with a struct and some
typedef magic: http://codepad.org/RNYyyFqc

So it kind of acts like an enum. But it's just a workaround, there
might be performance issues + switches don't work for structs. It was
just an experiment though.
May 10 2011
parent Nrgyzer <nrgyzer gmail.com> writes:
== Auszug aus Andrej Mitrovic (andrej.mitrovich gmail.com)'s Artikel
 I've ran into the same problem.
 There's a way to partially simulate an enum with a struct and some
 typedef magic: http://codepad.org/RNYyyFqc
 So it kind of acts like an enum. But it's just a workaround, there
 might be performance issues + switches don't work for structs. It was
 just an experiment though.
Works great - thanks!
May 11 2011
prev sibling parent Tomek =?UTF-8?B?U293acWEc2tp?= <just ask.me> writes:
Nrgyzer napisa=C5=82:

 I need enumerations with string[] as base type.
What for? --=20 Tomek
May 10 2011