MutexedAA.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 MutexedAA(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

MutexedAA!(int[int]) aa;
aa.setup();  // important!

assert(!aa.has(1));

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

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