associative arrays: iteration is finally here

Leandro Lucarella llucax at gmail.com
Thu Oct 29 12:16:14 PDT 2009


KennyTM~, el 30 de octubre a las 02:55 me escribiste:
> 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.)

Not if it's an Error instead of an exception. I think that should be the
case, .remove() check should be like bound check, something done at
non-release mode, not something to use in the regular flow of a program to
avoid using opIn().

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
Esta desenchufada la internet de ese televisor?
	-- Osvaldo Lucarella



More information about the Digitalmars-d mailing list