www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22237] New: AA.update is underspecified

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

          Issue ID: 22237
           Summary: AA.update is underspecified
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dlang.org
          Assignee: nobody puremagic.com
          Reporter: dkorpel live.nl

The spec gives this signature for .update on associative arrays:

 .update(Key key, Value delegate() create, Value delegate(Value) update)
https://dlang.org/spec/hash-map.html#properties But the actual implementation in druntime also allows returning void: ``` void main() { int[int] aa; aa.update(3, () => 3, (int x) {}); } ``` The idea being that the delegate can take the existing value by `ref` and update that way as well. This is how the update function is described:
 The update function provides a means to construct a new value via the 
 create delegate or update an existing value via the update delegate.
 Looks up key; if it exists applies the update delegate else evaluates 
 the create delegate and adds it to the associative array
This doesn't specify how the update delegate is actually applied, and whether you need to modify with ref, return a new value, or both. --
Aug 24 2021