Are associative arrays stable in D?

monarch_dodra monarchdodra at gmail.com
Wed Jul 17 02:48:04 PDT 2013


On Wednesday, 17 July 2013 at 08:31:00 UTC, Mike Parker wrote:
> On Tuesday, 16 July 2013 at 19:37:14 UTC, Gary Willoughby wrote:
>
>>
>> If however you remove the .byKey() call and use .keys instead, 
>> it works!
>>
>
> With byKey, you are iterating over a range of original key 
> values, meaning that attempting to remove any of them will 
> result in bad bahavior. With .keys, you are iterating over a 
> copied array of the keys, hence it's safe to remove them from 
> the aa.

I find it disturbing that the built-in property "keys" would dup 
an entire array, and then copy all the keys into that array, 
whereas the function "byKeys()" will simply allow you to iterate 
on the keys.

"keys" is in blatant violation of the "properties emulate 
members" mind-set.


More information about the Digitalmars-d-learn mailing list