View source code Display the source code in std/container/array.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

std.container.array.array - multiple declarations

Struct Array

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

Properties

Name Type Description
back [get] inout(T) Forward to opSlice().front and opSlice().back, respectively.
capacity [get] size_t Returns the maximum number of elements the container can store without (a) allocating memory, (b) invalidating iterators upon insertion.
dup [get] Array Duplicates the container. The elements themselves are not transitively duplicated.
empty [get] bool Property returning true if and only if the container has no elements.
front [get] inout(T) Forward to opSlice().front and opSlice().back, respectively.
length [set] size_t Sets the number of elements in the container to newSize. If newSize is greater than length, the added elements are added to unspecified positions in the container and initialized with T.init.
length [get] size_t Returns the number of elements in the container.

Methods

Name Description
clear Removes all contents from the container. The container decides how capacity is affected.
linearRemove Removes all elements belonging to r, which must be a range obtained originally from this container. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
opDollar Returns the number of elements in the container.
opEquals Comparison for equality.
opIndex Indexing operators yield or modify the value at a specified index.
opSlice Returns a range that iterates over elements of the container, in forward order.
opSlice Returns a range that iterates over elements of the container from index a up to (excluding) index b.
opSliceAssign Slicing operations execute an operation on an entire slice.
removeAny Picks one value in an unspecified position in the container, removes it from the container, and returns it. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
removeBack Removes the value at the back of the container. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
removeBack Removes howMany values at the front or back of the container. Unlike the unparameterized versions above, these functions do not throw if they could not remove howMany elements. Instead, if howMany > n, all elements are removed. The returned value is the effective number of elements removed. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
reserve Ensures sufficient capacity to accommodate e elements.

Aliases

Name Description
ConstRange Defines the container's primary range, which is a random-access range.
ImmutableRange Defines the container's primary range, which is a random-access range.
insert Inserts value to the front or back of the container. stuff can be a value convertible to T or a range of objects convertible to T. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
Range Defines the container's primary range, which is a random-access range.
stableRemoveAny Picks one value in an unspecified position in the container, removes it from the container, and returns it. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
stableRemoveBack Removes the value at the back of the container. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
stableRemoveBack Removes howMany values at the front or back of the container. Unlike the unparameterized versions above, these functions do not throw if they could not remove howMany elements. Instead, if howMany > n, all elements are removed. The returned value is the effective number of elements removed. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.

Templates

Name Description
insertAfter Inserts stuff before, after, or instead range r, which must be a valid range previously extracted from this container. stuff can be a value convertible to T or a range of objects convertible to T. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
insertBack Inserts value to the front or back of the container. stuff can be a value convertible to T or a range of objects convertible to T. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
insertBefore Inserts stuff before, after, or instead range r, which must be a valid range previously extracted from this container. stuff can be a value convertible to T or a range of objects convertible to T. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
opBinary Returns a new container that's the concatenation of this and its argument. opBinaryRight is only defined if Stuff does not define opBinary.
opOpAssign Forwards to insertBack(stuff).
opSliceOpAssign Slicing operations execute an operation on an entire slice.
opSliceUnary Slicing operations execute an operation on an entire slice.
replace Inserts stuff before, after, or instead range r, which must be a valid range previously extracted from this container. stuff can be a value convertible to T or a range of objects convertible to T. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
this Constructor taking a number of items
this Constructor taking an input range

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.

Struct Array

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

Properties

Name Type Description
back [get, set] bool Equivalent to opSlice().front and opSlice().back, respectively.
capacity [get] size_t Returns the maximum number of elements the container can store without (a) allocating memory, (b) invalidating iterators upon insertion.
dup [get] Array Returns a duplicate of the container. The elements themselves are not transitively duplicated.
empty [get] bool Property returning true if and only if the container has no elements.
front [get, set] bool Equivalent to opSlice().front and opSlice().back, respectively.
length [set] size_t Sets the number of elements in the container to newSize. If newSize is greater than length, the added elements are added to the container and initialized with ElementType.init.
length [get] size_t Returns the number of elements in the container.

Methods

Name Description
clear Removes all contents from the container. The container decides how capacity is affected.
linearRemove Removes all elements belonging to r, which must be a range obtained originally from this container. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
moveAt Indexing operators yield or modify the value at a specified index.
opIndex Indexing operators yield or modify the value at a specified index.
opIndexAssign Indexing operators yield or modify the value at a specified index.
opSlice Returns a range that iterates the container between two specified positions.
opSlice Returns a range that iterates over all elements of the container, in a container-defined order. The container should choose the most convenient and fast method of iteration for opSlice().
removeAny Picks one value in the container, removes it from the container, and returns it. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
removeBack Removes the value at the front or back of the container. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated. The optional parameter howMany instructs removal of that many elements. If howMany > n, all elements are removed and no exception is thrown.
removeBack Removes howMany values at the front or back of the container. Unlike the unparameterized versions above, these functions do not throw if they could not remove howMany elements. Instead, if howMany > n, all elements are removed. The returned value is the effective number of elements removed. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
reserve Ensures sufficient capacity to accommodate n elements.

Inner structs

Name Description
Range Defines the container's primary range.

Aliases

Name Description
insert Inserts stuff in the container. stuff can be a value convertible to ElementType or a range of objects convertible to ElementType.
linearInsert Same as insert(stuff) and stableInsert(stuff) respectively, but relax the complexity constraint to linear.
stableInsert Inserts stuff in the container. stuff can be a value convertible to ElementType or a range of objects convertible to ElementType.
stableInsertAfter Inserts stuff before, after, or instead range r, which must be a valid range previously extracted from this container. stuff can be a value convertible to ElementType or a range of objects convertible to ElementType. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
stableInsertBack Inserts value to the back of the container. stuff can be a value convertible to ElementType or a range of objects convertible to ElementType. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
stableInsertBefore Inserts stuff before, after, or instead range r, which must be a valid range previously extracted from this container. stuff can be a value convertible to ElementType or a range of objects convertible to ElementType. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
stableLinearInsert Same as insert(stuff) and stableInsert(stuff) respectively, but relax the complexity constraint to linear.
stableRemoveAny Picks one value in the container, removes it from the container, and returns it. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
stableRemoveBack Removes the value at the front or back of the container. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated. The optional parameter howMany instructs removal of that many elements. If howMany > n, all elements are removed and no exception is thrown.
stableReplace Inserts stuff before, after, or instead range r, which must be a valid range previously extracted from this container. stuff can be a value convertible to ElementType or a range of objects convertible to ElementType. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.

Templates

Name Description
insertAfter Inserts stuff before, after, or instead range r, which must be a valid range previously extracted from this container. stuff can be a value convertible to ElementType or a range of objects convertible to ElementType. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
insertBack Inserts value to the back of the container. stuff can be a value convertible to ElementType or a range of objects convertible to ElementType. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
insertBefore Inserts stuff before, after, or instead range r, which must be a valid range previously extracted from this container. stuff can be a value convertible to ElementType or a range of objects convertible to ElementType. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.
opBinary Returns a new container that's the concatenation of this and its argument.
opIndexOpAssign Indexing operators yield or modify the value at a specified index.
opOpAssign Forwards to insertAfter(this[], stuff).
replace Inserts stuff before, after, or instead range r, which must be a valid range previously extracted from this container. stuff can be a value convertible to ElementType or a range of objects convertible to ElementType. The stable version behaves the same, but guarantees that ranges iterating over the container are never invalidated.

Authors

Steven Schveighoffer, Andrei Alexandrescu

License

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at ).

Comments