Changing behavior of associative array

Dennis dkorpel at gmail.com
Sat Dec 16 22:44:16 UTC 2023


On Saturday, 16 December 2023 at 21:30:55 UTC, kdevel wrote:
> If you comment out this line
>
> ```
> //    m[f] = 1;
> ```
>
> in your main function of your posted code you can catch up with 
> your
> real programm insofar as you now need a ref parameter here, too.

That's because `m[f] = 1` initializes the associative array to 
something non-null. If you pass a `null` AA to a function which 
adds things, the caller will still have a null pointers. You can 
initialize a non-null empty AA like this:

```D
uint[Foo] m = new uint[Foo];
```

Then, `m` can be passed by value and you can make additions or 
removals which the caller sees, unless you assign a new AA in the 
function.


More information about the Digitalmars-d-learn mailing list