Problem with associative arrays

Jesse Phillips jessekphillips+D at gmail.com
Sat Mar 19 12:42:11 PDT 2011


Piotr Szturmaj Wrote:

> Thank you for your very complete answers :)
> 
> I was trying to avoid multiple AA key lookups while appending many 
> elements to dynamic array. It's clear now, that with D2 semantics it's 
> better to first build an array and then assign it to AA.

What everyone else said, but you can get a pointer with 'in'

void main() {
    uint[][uint] aa;
        
    aa[5] = new uint[0];
    auto temp = 5 in aa; // copy uint[] reference
    *temp ~= 1;
        
    assert(temp.length == 1 && (*temp)[0] == 1); // pass
    assert(aa[5].length == 1 && aa[5][0] == 1); // pass

}



More information about the Digitalmars-d-learn mailing list