associative arrays: iteration is finally here
KennyTM~
kennytm at gmail.com
Thu Oct 29 11:55:18 PDT 2009
On Oct 30, 09 01:14, bearophile wrote:
> KennyTM~:
>
>> Um what? aa["theKey"] = 1 doesn't fail, why should aa.remove("theKey")
>> be special?
>
> That's a different situation.
> You probably meant to say: If aa["theKey"]++; doesn't fail, why should aa.remove("theKey") be special?
>
>
>> void discard(K,V)(ref V[K] aa, in K key) {
>> if (!aa.remove(key)) assert(false);
>> }
>
> This is stupid. Part of the point of built-in AAs is to avoid to import things. If I need to import (or worse define) that discard template in all programs where I use an AA, then I will create my own AAs and I'll just import and use them in the first place.
>
> Bye,
> bearophile
This does not contradicts with .remove() not throwing an exception when
a key is not found. If you like you can put it in object.d.
(Moreover, having .remove() to throw means you can't delete any
dictionary items in nothrow functions. Sure you can silent it with
try/catch but that's expensive.)
More information about the Digitalmars-d
mailing list