Static Initialization of Associative Arrays

Tyro Tyro
Sun Mar 30 22:52:17 PDT 2008


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


More information about the Digitalmars-d-learn mailing list