Problem with associative arrays
Piotr Szturmaj
bncrbme at jadamspam.pl
Sun Mar 20 08:53:51 PDT 2011
Jesse Phillips wrote:
> 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
>
> }
>
Yes, I already used pointers but in other way:
uint[]* temp = &aa[5]; // copy uint[] reference
and it worked the same as using 'in'. However, I wasn't sure it's
completely safe.
More information about the Digitalmars-d-learn
mailing list