Empty associative array

Dukc ajieskola at gmail.com
Mon Aug 9 13:53:58 UTC 2021


On Monday, 9 August 2021 at 13:21:06 UTC, jfondren wrote:
>
> You get this with dynamic arrays as well.
>
> They're very convenient, scripting-language-like types, and 
> this comes with a few caveats that can be emphasized in 
> tutorials and learned. If the convenience isn't worth the 
> caveats for you, there's std.container.array and perhaps 
> https://code.dlang.org/packages/bcaa

I believe that's good design with dynamic arrays, because their 
pointer and length data are passed by copy. Testing a dynamic 
array against `null` means, in practice, testing whether it's 
`.ptr` property points to `null`. There is no such thing as a 
dynamic array that is itself `null` (unless it has `ref` storage 
class).

Associative arrays, however, are passed around by reference. When 
we test those against `null` we test whether we have an 
associative array at all, not whether that associative array 
points to any memory area.



More information about the Digitalmars-d mailing list