View source code
Display the source code in std/container/array.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

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, realloc and free for managing its own memory.

struct Array(T)
  
if (!is(Unqual!T == bool));

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.

Constructors

NameDescription
this Constructor taking a number of items.
this Constructor taking an input range

Properties

NameTypeDescription
back[get] inout(T)
capacity[get] size_t
dup[get] ArrayDuplicates the array. The elements themselves are not transitively duplicated.
empty[get] bool
front[get] inout(T)
length[get] size_t
length[set] size_tSets 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.

Methods

NameDescription
clear Removes all the elements from the array and releases allocated memory.
insertAfter 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 T. Both stable and non-stable version behave the same and guarantee that ranges iterating over the array are never invalidated.
insertBack 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.
insertBefore 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 T. Both stable and non-stable version behave the same and guarantee that ranges iterating over the array are never invalidated.
linearRemove Removes all elements belonging to r, which must be a range obtained originally from this array.
opBinary
opDollar
opEquals Comparison for equality.
opIndex
opOpAssign Forwards to insertBack.
opSlice
opSlice
opSliceAssign Slicing operators executing the specified operation on the entire slice.
opSliceOpAssign Slicing operators executing the specified operation on the entire slice.
opSliceUnary Slicing operators executing the specified operation on the entire slice.
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.
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.
removeBack 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, all elements are removed. The returned value is the effective number of elements removed. Both stable and non-stable versions behave the same and guarantee that ranges iterating over the array are never invalidated.
replace 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 T. Both stable and non-stable version behave the same and guarantee that ranges iterating over the array are never invalidated.
reserve Ensures sufficient capacity to accommodate e elements. If e < capacity, this method does nothing.

Aliases

NameDescription
ConstRange Defines the array's primary range, which is a random-access range.
ImmutableRange Defines the array's primary range, which is a random-access range.
insert 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.
Range Defines the array's primary range, which is a random-access range.
stableInsertBefore 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 T. Both stable and non-stable version behave the same and guarantee that ranges iterating over the array are never invalidated.
stableRemoveAny 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.
stableRemoveBack 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.
stableRemoveBack 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, all elements are removed. The returned value is the effective number of elements removed. Both stable and non-stable versions behave the same and guarantee that ranges iterating over the array are never invalidated.

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.

Example

typeof may give wrong result in case of classes defining opCall operator

https

//issues.dlang.org/show_bug.cgi?id=20589

destructor std.container.array.Array!(MyClass).Array.~this is @system so the unittest is @system too

class MyClass
{
    T opCall(T)(T p)
    {
        return p;
    }
}

Array!MyClass arr;

Struct Array

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

struct Array(T)
  
if (is(Unqual!T == bool));

Properties

NameTypeDescription
back[get, set] bool
capacity[get] size_t
dup[get] Array
empty[get] boolProperty returning true if and only if the array has no elements.
front[get, set] bool
length[get] size_tReturns the number of elements in the array.
length[set] size_tSets 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.

Methods

NameDescription
clear Removes all the elements from the array and releases allocated memory.
insertAfter 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 to bool. Both stable and non-stable version behave the same and guarantee that ranges iterating over the array are never invalidated.
insertBack 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.
insertBefore 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 to bool. Both stable and non-stable version behave the same and guarantee that ranges iterating over the array are never invalidated.
linearRemove Removes all elements belonging to r, which must be a range obtained originally from this array.
moveAt Indexing operators yielding or modifyng the value at the specified index.
opBinary
opIndex Indexing operators yielding or modifyng the value at the specified index.
opIndexAssign Indexing operators yielding or modifyng the value at the specified index.
opIndexOpAssign Indexing operators yielding or modifyng the value at the specified index.
opOpAssign Forwards to insertBack.
opSlice
opSlice
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.
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.
removeBack 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, all elements are removed. The returned value is the effective number of elements removed. Both stable and non-stable versions behave the same and guarantee that ranges iterating over the array are never invalidated.
replace 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 to bool. Both stable and non-stable version behave the same and guarantee that ranges iterating over the array are never invalidated.
reserve Ensures sufficient capacity to accommodate e elements. If e < capacity, this method does nothing.

Inner structs

NameDescription
Range Defines the array's primary range.

Aliases

NameDescription
insert 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.
linearInsert 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.
stableInsert 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.
stableInsertAfter 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 to bool. Both stable and non-stable version behave the same and guarantee that ranges iterating over the array are never invalidated.
stableInsertBack 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.
stableInsertBefore 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 to bool. Both stable and non-stable version behave the same and guarantee that ranges iterating over the array are never invalidated.
stableLinearInsert 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.
stableRemoveAny 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.
stableRemoveBack 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.
stableRemoveBack 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, all elements are removed. The returned value is the effective number of elements removed. Both stable and non-stable versions behave the same and guarantee that ranges iterating over the array are never invalidated.
stableReplace 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 to bool. Both stable and non-stable version behave the same and guarantee that ranges iterating over the array are never invalidated.

Authors

Andrei Alexandrescu

License

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