uniqueKey

Returns a unique key for the passed associative array. Reserves the key by assigning it a value.

Note: This function will end up in an endless loop if a narrow range of indexes is supplied and the associative array already contains values for all of them.

uniqueKey
(
AA : V[K]
V
K
)
(
ref AA aa
,
K min = 1
,
K max = K.max
,
V value = V.init
)
if (
isIntegral!K
)

Parameters

aa AA

Associative array to get a unique key for.

min K

Optional minimum key value; defaults to 1.

max K

Optional maximum key value; defaults to K.max, where K is the key type of the passed associative array.

value V

Optional value to assign to the key; defaults to V.init, where V is the value type of the passed associative array.

Return Value

Type: auto

A unique key for the passed associative array. There will exist an array entry for the key, with the value value.

Examples

string[int] aa;
immutable key = aa.uniqueKey;
assert(key > 0);
assert(key in aa);
assert(aa[key] == string.init);
import std.conv : to;

{
    string[int] aa;
    immutable key = aa.uniqueKey;
    assert(key in aa);
}
{
    long[long] aa;
    immutable key = aa.uniqueKey;
    assert(key in aa);
}
{
    shared bool[int] aa;
    immutable key = aa.uniqueKey;
    assert(key in aa);
}
{
    int[int] aa;
    immutable key = aa.uniqueKey(5, 6, 42);
    assert(key == 5);
    assert((aa[5] == 42), aa[5].to!string);
}