On Saturday, 9 February 2013 at 00:54:58 UTC, Andrej Mitrovic
wrote:
Feel free to file an enhancement request.
http://d.puremagic.com/issues/show_bug.cgi?id=9491
Hopefully that is clear.
On 2/7/13, Dan wrote:
> I believe this would have to be done at the level of
> AssociativeArray and can not be done as a helper function, since
> this set helper is still doing 3 hashes/lookups.
Feel free to file an enhancement request.
On 2/7/13 5:20 PM, Dan wrote:
For an associative array, what is the best idiom that allows for
checking if a key exists in the AA. If it does do something with the
value, if not initialize the value and then do something with it.
In this code: http://dpaste.dzfl.pl/daab318f
How would this piece
On Thursday, 7 February 2013 at 20:46:31 UTC, Andrej Mitrovic
wrote:
auto ref set(Hash, Key, Val)(Hash hash, Key key, Val val)
if (isAssociativeArray!Hash &&
is(Key : KeyType!Hash) &&
is(Val : ValueType!Hash))
{
if (auto res = key in hash)
{
return res;
}
On Thursday, February 07, 2013 21:46:20 Andrej Mitrovic wrote:
> On 2/7/13, Jonathan M Davis wrote:
> > I don't think that such a function exists
> > though.
>
> UFCS would do it:
>
> import std.traits;
>
> auto ref set(Hash, Key, Val)(Hash hash, Key key, Val val)
> if (isAssociativeArray!Hash
Jonathan M Davis:
But I certainly agree that it would be nice if there were a
function that
inserted the element if it wasn't already there and then
returns it regardless
of whether it was there or not. I don't think that such a
function exists
though.
Python dicts have a method that I don'
On 2/7/13, Jonathan M Davis wrote:
> I don't think that such a function exists
> though.
UFCS would do it:
import std.traits;
auto ref set(Hash, Key, Val)(Hash hash, Key key, Val val)
if (isAssociativeArray!Hash &&
is(Key : KeyType!Hash) &&
is(Val : ValueType!Hash))
{
if
On Thursday, February 07, 2013 21:20:46 Dan wrote:
> For an associative array, what is the best idiom that allows for
> checking if a key exists in the AA. If it does do something with
> the value, if not initialize the value and then do something with
> it.
>
> In this code: http://dpaste.dzfl.pl
For an associative array, what is the best idiom that allows for
checking if a key exists in the AA. If it does do something with
the value, if not initialize the value and then do something with
it.
In this code: http://dpaste.dzfl.pl/daab318f
How would this piece be improved? It looks like