findNextFree

Given an array of values this tries to find the next free value of which is NOT present within the given array.

If the array provided is emptied then a value will always be found and will be that of T.init.

@safe @nogc
bool
findNextFree
(
T
)
(
T[] used
,
ref T found
)
if (
__traits(isIntegral, T)
)

Parameters

used T[]

the array of values

found T

the found free value

Return Value

Type: bool

true if a free value was found otherwise false

Examples

Tests the findNextFree!(T)(T[], ref T) function

Case: First value is free + non-empty array

ubyte[] values = [1,2,3];

ubyte free;
bool status = findNextFree(values, free);
assert(status == true);
assert(isPresent(values, free) == false);

Tests the findNextFree!(T)(T[], ref T) function

Case: First value is unfree + non-empty array

ubyte[] values = [0,2,3];

ubyte free;
bool status = findNextFree(values, free);
assert(status == true);
assert(isPresent(values, free) == false);

Tests the findNextFree!(T)(T[], ref T) function

Case: Array is empty, first value should be T.init

ubyte[] values = [];

ubyte free;
bool status = findNextFree(values, free);
assert(status == true);
assert(free == ubyte.init);
assert(isPresent(values, free) == false);

Meta