www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14386] New: add setOrGet to AA

https://issues.dlang.org/show_bug.cgi?id=14386

          Issue ID: 14386
           Summary: add setOrGet to AA
           Product: D
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: code dawg.eu

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.

--
Mar 31 2015