Bug 14386 – add setOrGet to AA

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-31T21:28:23Z
Last change time
2018-11-23T13:26:56Z
Assigned to
No Owner
Creator
Martin Nowak

Comments

Comment #0 by code — 2015-03-31T21:28:23Z
The function is called setdefault in python and getOrElseUpdate in Scala. Allows to lookup a key or set a value with a single hash. This is also possible in C++ using iterators. https://docs.python.org/2/library/stdtypes.html#dict.setdefault http://www.scala-lang.org/api/2.10.1-RC1/scala/collection/mutable/HashMap.html#getOrElseUpdate(A,⇒B):B Another primitive that could work here is getLValue, but it requires the value type to have a distinct null value, so it's less nice to work with.
Comment #1 by stanislav.blinov — 2018-11-23T13:26:56Z
Since https://github.com/dlang/druntime/commit/0c92d13c7f8540bd91c3cce251d97ff39b84a486 (present in 2.082) there is now a require() function that does exactly that.