Thread overview
string[] enumerations
May 10, 2011
Nrgyzer
May 10, 2011
Andrej Mitrovic
May 11, 2011
Nrgyzer
May 10, 2011
Tomek Sowiński
May 10, 2011
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
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
Nrgyzer napisał:

> I need enumerations with string[] as base type.

What for?

-- 
Tomek

May 11, 2011
== 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!