delete hash[key] deprecated???

JAnderson ask at me.com
Sat Jul 19 13:57:33 PDT 2008


Stewart Gordon wrote:
> "Koroskin Denis" <2korden+dmd at gmail.com> wrote in message 
> news:op.uejmwq0sn8fdl4 at korden...
>> On Sat, 19 Jul 2008 16:39:18 +0400, Stewart Gordon 
>> <smjg_1998 at yahoo.com> wrote:
>>
>>> But .remove has to return something.  So how is this possible?
>>
>> It doesn't return anything now.
> 
> Are you missing my point, or guessing what Max meant?
> 
>>> And what would remove do if the key is already not in the AA?  Return 
>>> ValueType.init?  Throw an exception?
>>
>> I think returning null is ok. Otherwise a redundant check and a lookup 
>> will be necessary:
> 
> What if the value type has no null?

I think the compiler should remove the extra delete so that writing 
generic code is easy.  Alternatively the compiler could report an error 
if delete doesn't work with the given type however I less like that 
option.  Also you could do this if remove returned something:

auto value = map.remove("test");
assert(value); //Value not found.
delete value;

> 
>> Object[char[]] map;
>> if (auto o = "test" in map) { // this is redundant, in my opinion
>>     delete map.remove("test");
>> }
> <snip>
> 
> Indeed, the "auto o =" bit is unnecessary here.
> 
> Stewart.
> 

I


More information about the Digitalmars-d-learn mailing list