AA with dynamic array value

Craig Dillabaugh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 5 19:19:47 PDT 2016


On Wednesday, 6 July 2016 at 02:03:54 UTC, Adam D. Ruppe wrote:
> On Wednesday, 6 July 2016 at 01:58:31 UTC, Craig Dillabaugh 
> wrote:
>>         *(keyvalue) ~ value;   // This line fails.
>
> That should prolly be ~= instead of ~.

Ahh, I was so close.  Thank you that seems to do the trick.

However, now I have another issue.

For the following main function:

int main( string[] args) {

     int[][string] myAA;

     //int[] tmp;
     //tmp ~= 7;
     //myAA["world"] = tmp;

     insertValue( myAA, "hello", 1 );
     insertValue( myAA, "goodbye", 2 );
     insertValue( myAA, "hello", 3 );

     foreach (k; myAA.keys.sort)
     {
         writefln("%3s %d", k, myAA[k].length);
     }

     return 0;
}

If I run this, it prints out nothing.  However, if I uncomment 
adding an element for 'world' then it prints (as expected):

goodbye 1
hello 2
world 1

Why doesn't my function allow me to insert elements into an empty 
associative array, but succeeds for an AA with some element in it?



More information about the Digitalmars-d-learn mailing list