delete hash[key] deprecated???

Moritz Warning moritzwarning at web.de
Wed Jul 16 02:00:47 PDT 2008


On Tue, 15 Jul 2008 13:40:07 -0300, Leandro Lucarella wrote:

> Max Samukha, el 15 de julio a las 17:54 me escribiste:
>> >> >>If not, do I have to do:
>> >> >>auto c = hash["x"];
>> >> >>hash.remove["x"];
>> >> >>delete c;
>> >> >
>> >> >Yeah, you do.
>> >> 
>> >> 
>> >> No I don't.
>> >> 
>> >>    delete * cast(Object*) &hash["x"];
>> >
>> >Phew! That's much better! (!) o_O
>> 
>> An alternative hack:
>> 
>> delete *("x" in hash);
> 
> It just gets better and better ;)

FWIW:
I'm used to include this little helper in my code:
V get(V, K)(V[K] aa, K key)
{
	auto ptr = (key in aa);
	return ptr ? (*ptr) : null;
}

It boils down to:
delete aa.get("x");


I would appreciate if an associative array would return the plain value,
from a practical point.
The problem comes if you want to store 0, or null as key by purpose.
But I think it is programmers task in these rare circumstances to
insert a wrapped pointer.

-my2cents


More information about the Digitalmars-d-learn mailing list