Static Initialization of Associative Arrays

Simen Kjaeraas simen.kjaras at gmail.com
Mon Mar 31 01:03:40 PDT 2008


On Mon, 31 Mar 2008 07:52:17 +0200, Tyro[a.c.edwards] <no at spam.com> wrote:

> D v2.012 currently allows the following:
>
> int[char[]] eroMatrix = ["SA":1, "SB":2, "SP":3, "KK":4];
> foreach(k, v; eroMatrix)
>   writefln(k, "->", v);
>
> // output:
> SA->1
> SB->2
> SP->3
> KK->4
>
> However attempts to directly access a "key:value" pair results in an  
> ArrayBoundsError. Any idea why? Is there a temporary workaround  
> available?
>
> writefln(eroMatrix["SA"]) // ArrayBoundsError
>
> Thanks,
> Andrew

Weird. This works under DMD 1.026, and under DMD 2.012 if I don't use the  
literal.


More information about the Digitalmars-d-learn mailing list