Empty associative array

deadalnix deadalnix at gmail.com
Mon Aug 9 13:32:51 UTC 2021


On Monday, 9 August 2021 at 12:46:19 UTC, Mike Parker wrote:
> Do you mean you're passing the AA to those locations as a 
> function parameter? In that case, it's no different from the 
> behavior of dynamic arrays. The AA handle itself is not a 
> reference, so you need to explicitly pass it by reference:
>
> ```d
> void func(ref int[int] aa) { aa[3] = 3; }
>
> void main()
> {
>     int[int] aa;
>     func(aa);
>     assert(aa[3] == 10);
> }
> ```

This is cache, I need to keep it around. passing it by ref to 
function isn't going to cut it.

There are other solution, such as wrapping the AA into a struct a 
newing it, but this is introducing extra indirection for no good 
reasons.


More information about the Digitalmars-d mailing list