April 03, 2011
This is from the array documentation

enum Color { red, blue, green };
int value[Color.max + 1] = [ Color.blue:6, Color.green:2, Color.red:5 ];

It gives the following errors on dmd 2.052 on windows:

Error: Integer constant expression expected instead of Color.blue Error: Integer constant expression expected instead of Color.green Error: Integer constant expression expected instead of Color.red Error: Integer constant expression expected instead of Color.blue Error: Integer constant expression expected instead of Color.green Error: Integer constant expression expected instead of Color.red

Even if I set the enum elements manually the same errors occur. Seems constant enough for me though..

The following works
int value[Color.max + 1] = [ 1:6, 2:2, 0:5 ];
April 03, 2011
Well D has some problems with enums.. You can put those two in module scope and they will work. I'd also replace the docs' silly RHS style syntax from this:

int value[Color.max + 1];
to this:
int[Color.max + 1] value;

On 4/3/11, simendsjo <simen.endsjo@pandavre.com> wrote:
> This is from the array documentation
>
> enum Color { red, blue, green };
> int value[Color.max + 1] = [ Color.blue:6, Color.green:2, Color.red:5 ];
>
> It gives the following errors on dmd 2.052 on windows:
>
> Error: Integer constant expression expected instead of Color.blue Error: Integer constant expression expected instead of Color.green Error: Integer constant expression expected instead of Color.red Error: Integer constant expression expected instead of Color.blue Error: Integer constant expression expected instead of Color.green Error: Integer constant expression expected instead of Color.red
>
> Even if I set the enum elements manually the same errors occur. Seems
> constant enough for
> me though..
>
> The following works
> int value[Color.max + 1] = [ 1:6, 2:2, 0:5 ];
>