Re: How to use an associative array with array values.

2018-03-21 Thread Jesse Phillips via Digitalmars-d-learn

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.

2018-03-21 Thread tipdbmp via Digitalmars-d-learn

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.

2018-03-21 Thread Adam D. Ruppe via Digitalmars-d-learn

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.

2018-03-21 Thread tipdbmp via Digitalmars-d-learn

 // 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