Re: How to use an associative array with array values.
On Wednesday, 21 March 2018 at 18:31:29 UTC, tipdbmp wrote: I see. I guess the other would be: { int[8192] bar; int[8192][string] foo; foo["a"] = bar; foo["a"][8191] = -1; } https://run.dlang.io/is/AK2X2t Are you looking to use static arrays or dynamic? You can't use the new keyword if it static.
Re: How to use an associative array with array values.
I see. I guess the other would be: { int[8192] bar; int[8192][string] foo; foo["a"] = bar; foo["a"][8191] = -1; }
Re: How to use an associative array with array values.
On Wednesday, 21 March 2018 at 15:53:32 UTC, tipdbmp wrote: int[10][string] foo; One option is to initialize like this --- void main() { int[10][string] foo; if("a" !in foo) foo["a"] = [0,0,0,0,0,0,0,0,0,0]; // set all to zero to create the key foo["a"][4] = 4; // now valid to set individual element } ---
How to use an associative array with array values.
// foo is an associative array/hashtable with // key type: string // value type: int[10] // int[10][string] foo; // foo["a"] = new int[10]; // Range violation at runtime // foo["a"][0] = 1; // Range violation at runtime