delete hash[key] deprecated???

Leandro Lucarella llucax at gmail.com
Sat Jul 19 20:51:53 PDT 2008


Stewart Gordon, el 19 de julio a las 13:39 me escribiste:
> 
> "Max Samukha" <samukha at voliacable.com.removethis> wrote in message news:d85384p9e1heua1f8f6vn2cesd9cosjlrc at 4ax.com...
> >On Fri, 18 Jul 2008 22:27:16 +0100, "Stewart Gordon"
> ><smjg_1998 at yahoo.com> wrote:
> >
> >>"Max Samukha" <samukha at voliacable.com.removethis> wrote in message
> >>news:9d2r74tuopl0dt05sgnkagss4gu4824k9m at 4ax.com...
> >><snip>
> >>>If 'remove' was modified to return the removed value, more compact
> >>>syntax would be possible:
> >>>
> >>>delete hash.remove("x");
> >><snip>
> >>
> >>And what would remove do if the key is already not in the AA?  Return
> >>ValueType.init?  Throw an exception?
> >>
> >>Stewart.
> >
> >Three options:
> >
> >1. Throw an assert exception if the program was built with a debug
> >switch
> 
> And do what if the program wasn't built with a "debug switch"?  Moreover, I personally think that debug switches should be saved for programmer-defined debug 
> code.

If the idea was to add an assert in the remove code, I guess he meant not
to raise an assert exception if compiled with the release flag.

In case the exception is not raised that could just be undefined behavior
(SIGSEGV or whatever).

> >2. Always throw an exception
> >3. Make 'remove' return a pointer to the value
> 
> And so if the key isn't present, return null.  Hmm....  I guess it would be the programmer's responsibility not to keep lots of these pointers alive and 
> thereby prevent the AA nodes from being GC'd.  Hmm....

I think this solution can be perfectly viable too.

But I still think delete hash["x"]; should just work =)

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Software is like sex: it's better when it's free.
	-- Linus Torvalds


More information about the Digitalmars-d-learn mailing list