Search for, o/w create element for AA
Moritz Maxeiner via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 19 11:39:57 PDT 2017
On Monday, 19 June 2017 at 15:19:19 UTC, Q. Schroll wrote:
> I have to lookup x twice and it seems that there is no way
> around it. Can't I tell the AA to set a value for a given key
> if it doesn't already have one
> (1) with only one lookup, and
> (2) in a safe way?
AFAIK the builtin associate array implementation exposes neither
such a function, nor other functions which you can use to
assemble this, so no, you cannot do this with only one lookup
(currently).
Though I can't see why it couldn't be added, seems fairly
straight forward.
The best you can do with the builtin associative arrays right now
is make sure that the `toHash` of your key type is cached.
More information about the Digitalmars-d-learn
mailing list