std.container.array

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

Types 3

private structRangeT(A)
Fields
private A[1] _outer_
private size_t _a
Methods
private inout(A) _outer() @property ref inout
RangeT save() @property
bool empty() @property @safe pure nothrow const
size_t length() @property @safe pure nothrow const
inout(E) front() @property ref inout
inout(E) back() @property ref inout
void popFront() @safe @nogc pure nothrow
void popBack() @safe @nogc pure nothrow
inout(E) opIndex(size_t i) ref inout
RangeT opSlice(size_t i, size_t j)
RangeT!(const(A)) opSlice() const
RangeT!(const(A)) opSlice(size_t i, size_t j) const
Constructors
this(ref A data, size_t a, size_t b)
structArray(T) if (!is(immutable T == immutable bool))

_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.

Note

When using 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.

Fields
private Data _data
Methods
bool opEquals(const Array rhs) constComparison for equality.
bool opEquals(ref const Array rhs) constditto
Array dup() @propertyDuplicates the array. The elements themselves are not transitively duplicated.
bool empty() @property constReturns: `true` if and only if the array has no elements.
size_t length() @property constReturns: The number of elements in the array.
size_t opDollar() constditto
size_t capacity() @propertyReturns: The maximum number of elements the array can store without reallocating memory and invalidating iterators upon insertion.
inout(T)[] data() inout @systemReturns: the internal representation of the array.
void reserve(size_t elements)Ensures sufficient capacity to accommodate `e` elements. If `e < capacity`, this method does nothing.
Range opSlice()Returns: A range that iterates over elements of the array in forward order.
ConstRange opSlice() const
ImmutableRange opSlice() immutable
Range 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) const
ImmutableRange opSlice(size_t i, size_t j) immutable
inout(T) front() @property ref inoutReturns: The first element of the array.
inout(T) back() @property ref inoutReturns: The last element of the array.
inout(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)ditto
void opSliceUnary(string op)() if (op == "++" || op == "--")ditto
void opSliceUnary(string op)(size_t i, size_t j) if (op == "++" || op == "--")ditto
void opSliceOpAssign(string op)(T value)ditto
void opSliceOpAssign(string op)(T value, size_t i, size_t j)ditto
Array 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))ditto
size_t insertAfter(Stuff)(Range r, Stuff stuff) if (isImplicitlyConvertible!(Stuff, T) || isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, T))ditto
size_t replace(Stuff)(Range r, Stuff stuff) if (isInputRange!Stuff && isImplicitlyConvertible!(ElementType!Stuff, T))ditto
size_t replace(Stuff)(Range r, Stuff stuff) if (isImplicitlyConvertible!(Stuff, T))ditto
Range linearRemove(Range r)Removes all elements belonging to `r`, which must be a range obtained originally from this array.
Constructors
this(U[] values...)Constructor taking a number of items.
this(T single)ditto
this(Range r)Constructor taking an input range
Nested Templates
Payload
structArray(T) if (is(immutable T == immutable bool))

_Array specialized for bool. Packs together values efficiently by allocating one bit per element.

Fields
uint bitsPerWord
private RefCounted!(Data, RefCountedAutoInitialize.no) _store
Methods
private size_t[] data() @property ref
bool empty() @propertyProperty returning `true` if and only if the array has no elements.
Array dup() @propertyReturns: A duplicate of the array.
size_t length() @property constReturns the number of elements in the array.
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()Returns: A range that iterates over all elements of the array in forward order.
Range opSlice(size_t a, size_t b)Returns: A range that iterates the array between two specified positions.
bool front() @propertyReturns: The first element of the array.
void front(bool value) @propertyDitto
bool back() @propertyReturns: The last element of the array.
void back(bool value) @propertyDitto
bool opIndex(size_t i)Indexing operators yielding or modifyng the value at the specified index.
void opIndexAssign(bool value, size_t i)ditto
void opIndexOpAssign(string op)(bool value, size_t i)ditto
T moveAt(size_t i)Ditto
Array!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))ditto
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)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))ditto
size_t replace(Stuff)(Range r, Stuff stuff) if (is(Stuff : bool))ditto
Range linearRemove(Range r)Removes all elements belonging to `r`, which must be a range obtained originally from this array.
Constructors
this(U[] values...)Constructor taking a number of items.
this(Range r)Constructor taking an input range
Nested Templates
Data
RangeDefines the array's primary range.