Array

Generic, manually managed, array.

Array(T) implements a single-dimension array of uncollected memory. It internally allocates memory blocks to minimize the reallocation fingerprints, allowing insertions to be 2 times faster than built-in arrays.

Its layout differs from built-in D's dynamic arrays and they cannot be cast as T[] however, most of the slicing operations are possible.

Manual management implies that destruct() must be called on the array when it goes out of scope. destruct() is only called on the content when the specialization is a struct() or a union). Classes and pointers must be freed by hand.

Constructors

this
this(E elements)

Constructs the array with a list of T.

this
this(E[] elements...)

Constructs the array with a D array of T.

this
this(auto ref E value)

Constructs by dispatching to the existing opAssign overloads.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Postblit

A postblit is present on this object, but not explicitly documented in the source.

Alias This

opSlice

Allows to use the array as a D built-in array.

Members

Aliases

put
alias put = opOpAssign!"~"

Support for output ranges.

Functions

blockCount
size_t blockCount()

Indicates how many block the array is made of.

dup
Array!T dup()

Returns a mutable (deep) copy of the array.

granularity
void granularity(uint value)

Sets the memory allocation block-size. value should be set to 16 or 4096 (the default).

granurality
uint granurality()

Indicates the memory allocation block-size.

length
size_t length()
void length(V value)

Sets or gets the element count.

opApply
int opApply(scope int delegate(ref T) dg)

Support for the foreach operator.

opApplyReverse
int opApplyReverse(scope int delegate(ref T) dg)

Support for the foreach_reverse operator.

opAssign
void opAssign(auto ref Array!E elements)

Assign another Array!T.

opAssign
void opAssign(auto ref E[] elements)

Assigns a D array.

opAssign
void opAssign(auto ref E elements)

Assigns an inpunt range.

opBinary
typeof(this) opBinary(auto ref R rhs)

Support for the cat operator

opDollar
size_t opDollar()

Support for the dollar operator.

opEquals
bool opEquals(auto ref A array)

Support for equality tests.

opIndex
T opIndex(size_t i)

Support for the array syntax.

opIndexAssign
void opIndexAssign(ref T item, size_t i)
void opIndexAssign(T item, size_t i)
void opIndexAssign(TemplateArgsOf!(T)[0][] item, size_t i)

Support for the array syntax.

opOpAssign
typeof(this) opOpAssign(auto ref E[] elements)

Support for the cat operator.

opOpAssign
typeof(this) opOpAssign(T aElement)

Support for the cat operator.

opSlice
auto ref opSlice(size_t lo, size_t hi)

Returns a slice of the array. The memory is not duplicated.

opSlice
T[] opSlice()

Returns the array as a D slice. The memory is not duplicated.

opSliceAssign
void opSliceAssign(T value)
void opSliceAssign(T value, size_t lo, size_t hi)

Support for filling the array with a single element.

ptr
Ptr ptr()

Pointer to the first element. As it's always assigned It cannot be used to determine if the array is empty.

put
void put(auto ref E[] elements)

Support for output ranges.

range
auto range()

Returns an input range with an assignable front.

toHash
size_t toHash()

Support for associative arrays.

toString
string toString()

Returns the string representation of the array.

typedPtr
T* typedPtr()

Typed pointer to the first element.

Examples

1 Array!int a;
2 a.length = 2;
3 a[] = 1;
4 assert(a[0] == 1);
5 assert(a[1] == 1);

Meta