License
(See accompanying file LICENSE_1_0.txt or copy at boost.org/LICENSE_1_0.txt).
This module provides an Array type with deterministic memory usage not reliant on the GC, as an alternative to the built-in arrays.
This module is a submodule of std.container.
Source: std/container/array.d
(See accompanying file LICENSE_1_0.txt or copy at boost.org/LICENSE_1_0.txt).
_Array type with deterministic control of memory. The memory allocated for the array is reclaimed as soon as possible; there is no reliance on the garbage collector. Array uses malloc, realloc and free for managing its own memory.
This means that pointers to elements of an Array will become dangling as soon as the element is removed from the Array. On the other hand the memory allocated by an Array will be scanned by the GC and GC managed objects referenced from an Array will be kept alive.
Array with range-based functions like those in std.algorithm,
Array must be sliced to get a range (for example, use array[].map! instead of array.map!). The container itself is not a range.
private Data _datasize_t capacity() @propertyReturns: The maximum number of elements the array can store without reallocating memory and invalidating iterators upon insertion.void reserve(size_t elements)Ensures sufficient capacity to accommodate `e` elements. If `e < capacity`, this method does nothing.ConstRange opSlice() constImmutableRange opSlice() immutableRange opSlice(size_t i, size_t j)Returns: A range that iterates over elements of the array from index `i` up to (excluding) index `j`.ConstRange opSlice(size_t i, size_t j) constImmutableRange opSlice(size_t i, size_t j) immutableinout(T) opIndex(size_t i) ref inoutReturns: The element or a reference to the element at the specified index.void opSliceAssign(T value)Slicing operators executing the specified operation on the entire slice.void opSliceAssign(T value, size_t i, size_t j)dittovoid opSliceUnary(string op)() if (op == "++" || op == "--")dittovoid opSliceUnary(string op)(size_t i, size_t j) if (op == "++" || op == "--")dittovoid opSliceOpAssign(string op)(T value)dittovoid opSliceOpAssign(string op)(T value, size_t i, size_t j)dittoArray opBinary(string op, Stuff)(Stuff stuff) if (op == "~")Returns: A new array which is a concatenation of `this` and its argument.void opOpAssign(string op, Stuff)(auto ref Stuff stuff) if (op == "~")Forwards to `insertBack`.void clear()Removes all the elements from the array and releases allocated memory.void length(size_t newLength) @propertySets the number of elements in the array to `newLength`. If `newLength` is greater than `length`, the new elements are added to the end of the array and initialized with `T.init`. If `T` is a `stru...T removeAny()Removes the last element from the array and returns it. Both stable and non-stable versions behave the same and guarantee that ranges iterating over the array are never invalidated.size_t insertBack(Stuff)(Stuff stuff) if (isImplicitlyConvertible!(Stuff, T) ||
isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, T))Inserts the specified elements at the back of the array. `stuff` can be a value convertible to `T` or a range of objects convertible to `T`.void removeBack()Removes the value from the back of the array. Both stable and non-stable versions behave the same and guarantee that ranges iterating over the array are never invalidated.size_t removeBack(size_t howMany)Removes `howMany` values from the back of the array. Unlike the unparameterized versions above, these functions do not throw if they could not remove `howMany` elements. Instead, if `howMany > n`, ...size_t insertBefore(Stuff)(Range r, Stuff stuff) if (isImplicitlyConvertible!(Stuff, T))Inserts `stuff` before, after, or instead range `r`, which must be a valid range previously extracted from this array. `stuff` can be a value convertible to `T` or a range of objects convertible to...size_t insertBefore(Stuff)(Range r, Stuff stuff) if (isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, T))dittosize_t insertAfter(Stuff)(Range r, Stuff stuff) if (isImplicitlyConvertible!(Stuff, T) ||
isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, T))dittosize_t replace(Stuff)(Range r, Stuff stuff) if (isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, T))dittoRange linearRemove(Range r)Removes all elements belonging to `r`, which must be a range obtained originally from this array.this(T single)dittoPayload_Array specialized for bool. Packs together values efficiently by allocating one bit per element.
size_t capacity() @propertyReturns: The maximum number of elements the array can store without reallocating memory and invalidating iterators upon insertion.void reserve(size_t e)Ensures sufficient capacity to accommodate `e` elements. If `e < capacity`, this method does nothing.Range opSlice(size_t a, size_t b)Returns: A range that iterates the array between two specified positions.bool opIndex(size_t i)Indexing operators yielding or modifyng the value at the specified index.void opIndexAssign(bool value, size_t i)dittovoid opIndexOpAssign(string op)(bool value, size_t i)dittoT moveAt(size_t i)DittoArray!bool opBinary(string op, Stuff)(Stuff rhs) if (op == "~")Returns: A new array which is a concatenation of `this` and its argument.Array!bool opOpAssign(string op, Stuff)(Stuff stuff) if (op == "~")Forwards to `insertBack`.void clear()Removes all the elements from the array and releases allocated memory.void length(size_t newLength) @propertySets the number of elements in the array to `newLength`. If `newLength` is greater than `length`, the new elements are added to the end of the array and initialized with `false`.T removeAny()Removes the last element from the array and returns it. Both stable and non-stable versions behave the same and guarantee that ranges iterating over the array are never invalidated.size_t insertBack(Stuff)(Stuff stuff) if (is(Stuff : bool))Inserts the specified elements at the back of the array. `stuff` can be a value convertible to `bool` or a range of objects convertible to `bool`.size_t insertBack(Stuff)(Stuff stuff) if (isInputRange!Stuff && is(ElementType!Stuff : bool))dittovoid removeBack()Removes the value from the back of the array. Both stable and non-stable versions behave the same and guarantee that ranges iterating over the array are never invalidated.size_t removeBack(size_t howMany)Removes `howMany` values from the back of the array. Unlike the unparameterized versions above, these functions do not throw if they could not remove `howMany` elements. Instead, if `howMany > n`, ...size_t insertBefore(Stuff)(Range r, Stuff stuff)Inserts `stuff` before, after, or instead range `r`, which must be a valid range previously extracted from this array. `stuff` can be a value convertible to `bool` or a range of objects convertible...size_t insertAfter(Stuff)(Range r, Stuff stuff) if (isImplicitlyConvertible!(Stuff, T) ||
isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, T))dittoRange linearRemove(Range r)Removes all elements belonging to `r`, which must be a range obtained originally from this array.DataRangeDefines the array's primary range.