RehashingAA.update

Updates the value for the key key in the internal associative array, invoking the first of the passed delegate to insert a new value if it doesn't exist, or the second selegate to modify it in place if it does.

Note: Doesn't compile with compilers earlier than version 2.088.

struct RehashingAA(AA : V[K], V, K)
static if(__VERSION__ >= 2088L)
void
update
(
U
)
(
K key
,
scope V delegate
()
createDg
,
scope U delegate
(
K
)
updateDg
)
if (
is(U == V) ||
is(U == void)
)

Parameters

key K

Key.

createDg V delegate
()

Delegate to invoke to create a new value if it doesn't exist.

updateDg U delegate
(
K
)

Delegate to invoke to update an existing value.

Examples

RehashingAA!(int[int]) aa;

assert(1 !in aa);

aa.update(1,
    () => 42,
    (int i) => i + 1);
assert(aa[1] == 42);

aa.update(1,
    () => 42,
    (int i) => i + 1);
assert(aa[1] == 43);