[Issue 22237] New: AA.update is underspecified
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Aug 24 20:02:51 UTC 2021
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 at puremagic.com
Reporter: dkorpel at 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.
--
More information about the Digitalmars-d-bugs
mailing list