July 15, 2008
Stewart Gordon, el 15 de julio a las 01:14 me escribiste:
> "Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message
> news:fopjrt$1b2c$1@digitalmars.com...
> <snip>
> >>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

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
More people die from a champagne-cork popping,
than from poison spiders
July 15, 2008
On Tue, 15 Jul 2008 11:13:33 -0300, Leandro Lucarella <llucax@gmail.com> wrote:

>Stewart Gordon, el 15 de julio a las 01:14 me escribiste:
>> "Jarrett Billingsley" <kb3ctd2@yahoo.com> wrote in message
>> news:fopjrt$1b2c$1@digitalmars.com...
>> <snip>
>> >>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);
July 15, 2008
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 ;)

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
22% of the time a pizza will arrive faster than an ambulance in Great-Britain
July 15, 2008
On Tue, 15 Jul 2008 20:40:07 +0400, Leandro Lucarella <llucax@gmail.com> 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 ;)
>

But you still have to remove a dead pointer from a collection:

delete *("x" in hash);
hash.remove("x");
July 16, 2008
On Wed, 16 Jul 2008 01:23:30 +0400, "Koroskin Denis" <2korden+dmd@gmail.com> wrote:

>But you still have to remove a dead pointer from a collection:
>
>delete *("x" in hash);
>hash.remove("x");

If 'remove' was modified to return the removed value, more compact syntax would be possible:

delete hash.remove("x");

Also, there would be no need to search for the value twice and introduce a temporary when the removed value is needed for further processing:

// do something with the value, for example, pass it to a function
foo(hash.remove("x"));

instead of:
auto v = hash["x"];
hash.remove("x");
foo(v);
July 16, 2008
Max Samukha wrote:
> On Wed, 16 Jul 2008 01:23:30 +0400, "Koroskin Denis"
> <2korden+dmd@gmail.com> wrote:
> 
>> But you still have to remove a dead pointer from a collection:
>>
>> delete *("x" in hash);
>> hash.remove("x");
> 
> If 'remove' was modified to return the removed value, more compact
> syntax would be possible:
> 
> delete hash.remove("x");
> 
> Also, there would be no need to search for the value twice and
> introduce a temporary when the removed value is needed for further
> processing:
> 
> // do something with the value, for example, pass it to a function
> foo(hash.remove("x"));
> 
> instead of:
> auto v = hash["x"];
> hash.remove("x");
> foo(v);

I think this is a good idea.

-Joel
July 16, 2008
JAnderson wrote:
> Max Samukha wrote:
>> On Wed, 16 Jul 2008 01:23:30 +0400, "Koroskin Denis"
>> <2korden+dmd@gmail.com> wrote:
>>
>>> But you still have to remove a dead pointer from a collection:
>>>
>>> delete *("x" in hash);
>>> hash.remove("x");
>>
>> If 'remove' was modified to return the removed value, more compact
>> syntax would be possible:
>>
>> delete hash.remove("x");
>>
>> Also, there would be no need to search for the value twice and
>> introduce a temporary when the removed value is needed for further
>> processing:
>>
>> // do something with the value, for example, pass it to a function
>> foo(hash.remove("x"));
>>
>> instead of:
>> auto v = hash["x"];
>> hash.remove("x");
>> foo(v);
> 
> I think this is a good idea.

Seconded!

Regan Heath
July 16, 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
July 18, 2008
Regan Heath <regan@netmail.co.nz> wrote:

> JAnderson wrote:
>> Max Samukha wrote:
>>> On Wed, 16 Jul 2008 01:23:30 +0400, "Koroskin Denis"
>>> <2korden+dmd@gmail.com> wrote:
>>>
>>>> But you still have to remove a dead pointer from a collection:
>>>>
>>>> delete *("x" in hash);
>>>> hash.remove("x");
>>>
>>> If 'remove' was modified to return the removed value, more compact
>>> syntax would be possible:
>>>
>>> delete hash.remove("x");
>>>
>>> Also, there would be no need to search for the value twice and
>>> introduce a temporary when the removed value is needed for further
>>> processing:
>>>
>>> // do something with the value, for example, pass it to a function
>>> foo(hash.remove("x"));
>>>
>>> instead of:
>>> auto v = hash["x"];
>>> hash.remove("x");
>>> foo(v);
>>  I think this is a good idea.
>
> Seconded!
>
> Regan Heath

Thirded!

-- Simen
July 18, 2008
"Max Samukha" <samukha@voliacable.com.removethis> wrote in message news:9d2r74tuopl0dt05sgnkagss4gu4824k9m@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.

-- 
My e-mail address is valid but not my primary mailbox.  Please keep replies on the 'group where everybody may benefit.