foreach AA key char[] type change

bearophile bearophileHUGS at lycos.com
Sun Jun 6 04:45:35 PDT 2010


Steven Schveighoffer:
> Probably because you aren't allowed to change keys for AAs.  Passing the  
> key as a char[] type would allow that.

Modifying AA keys after they are inserted in the AA is bad because their hash value and position inside the AA doesn't get recomputed.

The current design/behaviour is surprising and bad, because I have asked for a key type and the runtime/compiler gives me a different key type (forcing me to use casts). There are two possible behaviours that I can accept here:

1) to disallow AAs with mutable keys, their literals and definition too (as Python does);
2) or to allow mutable keys (and hope the programmer will not mutate them) (as I think D1 does).

Thank you for your answer,
bye,
bearophile


More information about the Digitalmars-d-learn mailing list