The OpenD Programming Language

assumeSafeAppend

Assume that it is safe to append to this array. Appends made to this array after calling this function may append in place, even if the array was a slice of a larger array to begin with.

Use this only when it is certain there are no elements in use beyond the array in the memory block. If there are, those elements will be overwritten by appending to this array.

Warning: Calling this function, and then using references to data located after the given array results in undefined behavior.

ref nothrow @system
inout(T[])
assumeSafeAppend
(
T
)
(
auto ref inout(T[]) arr
)

Return Value

Type: inout(T[])

The input is returned.

Examples

int[] a = [1, 2, 3, 4];

// Without assumeSafeAppend. Appending relocates.
int[] b = a [0 .. 3];
b ~= 5;
assert(a.ptr != b.ptr);

debug(SENTINEL) {} else
{
    // With assumeSafeAppend. Appending overwrites.
    int[] c = a [0 .. 3];
    c.assumeSafeAppend() ~= 5;
    assert(a.ptr == c.ptr);
}

Meta