digitalmars.D.learn - How to use an associative array with array values.
- tipdbmp (7/7) Mar 21 2018 // foo is an associative array/hashtable with
- Adam D. Ruppe (11/12) Mar 21 2018 One option is to initialize like this
- tipdbmp (7/7) Mar 21 2018 I see. I guess the other would be:
- Jesse Phillips (4/11) Mar 21 2018 https://run.dlang.io/is/AK2X2t
// 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
Mar 21 2018
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 } ---
Mar 21 2018
I see. I guess the other would be: { int[8192] bar; int[8192][string] foo; foo["a"] = bar; foo["a"][8191] = -1; }
Mar 21 2018
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.
Mar 21 2018