TypedAllocator.shrinkArray

Shrinks an array by delta elements using allocatorFor!(T[]).

If arr.length < delta, does nothing and returns false. Otherwise, destroys the last arr.length - delta elements in the array and then reallocates the array's buffer. If reallocation fails, fills the array with default-initialized data.

struct TypedAllocator(PrimaryAllocator, Policies...)
bool
shrinkArray
(
T
)
(
ref T[] arr
,
size_t delta
)

Parameters

T

element type of the array being created

arr T[]

a reference to the array being shrunk

delta size_t

number of elements to remove (upon success the new length of arr is arr.length - delta)

Return Value

Type: bool

true upon success, false if memory could not be reallocated. In the latter case arr[$ - delta .. $] is left with default-initialized elements.

Throws

The first two overloads throw only if the used allocator's primitives do. The overloads that involve copy initialization deallocate memory and propagate the exception if the copy operation throws.

Meta