[Issue 17526] New: Add a set method for AA
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Jun 19 15:14:33 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17526
Issue ID: 17526
Summary: Add a set method for AA
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: qs.il.paperinik at gmail.com
One cannot add values to an AA typed const(V)[K] because aa[key] is typed
const(V). Add a method that has the semantics of this
V set(K, V)(ref const(V)[const(K)] aa, auto ref const(K) key, lazy const(V)
value)
{
if (auto valPtr = key in aa) return *valPtr;
// cast away const as initialization is okay:
return (cast() aa[key]) = value();
}
but without double lookup and without unsafe cast.
The question arose here:
https://forum.dlang.org/post/rwklxqwbsjzmcugsrxfq@forum.dlang.org
--
More information about the Digitalmars-d-bugs
mailing list