| Thread overview | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 11, 2008 [2.0] Remove deprecation of delete hash[key] (and change its semantics) | ||||
|---|---|---|---|---|
| ||||
When doing: delete hash[key] in D 1.0, there is a deprecation error about being an old syntax for hash.remove(key). So now, if you have an hash of objects, and you want to do explicit memory deallocation, you have to do something like this:
auto tmp = hash[key];
hash.remove(key);
delete tmp;
Which is ugly and nonsense. Maybe remove it from 1.0 could be contraversial, but I think there is no point in conserving this ugly behaviour in 2.0.
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Vaporeso sostenía a rajacincha la teoría del No-Water, la cual le pertenecía y versaba lo siguiente: "Para darle la otra mejilla al fuego, éste debe ser apagado con alpargatas apenas húmedas".
| ||||
February 11, 2008 Re: [2.0] Remove deprecation of delete hash[key] (and change its semantics) | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Leandro Lucarella | On Mon, 11 Feb 2008 12:18:10 -0200, Leandro Lucarella wrote:
> When doing: delete hash[key] in D 1.0, there is a deprecation error about being an old syntax for hash.remove(key). So now, if you have an hash of objects, and you want to do explicit memory deallocation, you have to do something like this:
>
> auto tmp = hash[key];
> hash.remove(key);
> delete tmp;
>
> Which is ugly and nonsense. Maybe remove it from 1.0 could be contraversial, but I think there is no point in conserving this ugly behaviour in 2.0.
I can't test it now, but I would think that hash.remove(key) would return the removed value. Couldn't find mention in the docs but if it is true
delete hash.remove(key);
should work.
| |||
February 11, 2008 Re: [2.0] Remove deprecation of delete hash[key] (and change its | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | Jesse Phillips:
> I can't test it now, but I would think that hash.remove(key) would return
> the removed value. Couldn't find mention in the docs but if it is true
> delete hash.remove(key);
In DMD 1.025 hash.remove(key) is a void.
Bye,
bearophile
| |||
February 11, 2008 Re: [2.0] Remove deprecation of delete hash[key] (and change its | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jesse Phillips | Jesse Phillips Wrote:
> On Mon, 11 Feb 2008 12:18:10 -0200, Leandro Lucarella wrote:
>
> > When doing: delete hash[key] in D 1.0, there is a deprecation error about being an old syntax for hash.remove(key). So now, if you have an hash of objects, and you want to do explicit memory deallocation, you have to do something like this:
> >
> > auto tmp = hash[key];
> > hash.remove(key);
> > delete tmp;
> >
> > Which is ugly and nonsense. Maybe remove it from 1.0 could be contraversial, but I think there is no point in conserving this ugly behaviour in 2.0.
>
> I can't test it now, but I would think that hash.remove(key) would return the removed value. Couldn't find mention in the docs but if it is true
>
> delete hash.remove(key);
>
> should work.
Even if remove does return the removed value, it won't work, since delete needs a lvalue.
| |||
March 05, 2008 Re: [2.0] Remove deprecation of delete hash[key] (and change its | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Leonard Dahlmann | Leonard Dahlmann wrote: > Jesse Phillips Wrote: > >> On Mon, 11 Feb 2008 12:18:10 -0200, Leandro Lucarella wrote: >> >>> When doing: delete hash[key] in D 1.0, there is a deprecation error >>> about being an old syntax for hash.remove(key). So now, if you have an >>> hash of objects, and you want to do explicit memory deallocation, you >>> have to do something like this: >>> >>> auto tmp = hash[key]; >>> hash.remove(key); >>> delete tmp; >>> >>> Which is ugly and nonsense. Maybe remove it from 1.0 could be >>> contraversial, but I think there is no point in conserving this ugly >>> behaviour in 2.0. >> I can't test it now, but I would think that hash.remove(key) would return the removed value. Couldn't find mention in the docs but if it is true >> >> delete hash.remove(key); >> >> should work. > > Even if remove does return the removed value, it won't work, > since delete needs a lvalue. I added a bug/enhancement report for that: http://d.puremagic.com/issues/show_bug.cgi?id=1893 -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply