The OpenD Programming Language

std.array

Functions and types that manipulate built-in arrays and associative arrays.

This module provides all kinds of functions to create, manipulate or convert arrays:

Function NameDescription
arrayReturns a copy of the input in a newly allocated dynamic array.
appenderReturns a new Appender or RefAppender initialized with a given array.
assocArrayReturns a newly allocated associative array from a range of key/value tuples.
byPairConstruct a range iterating over an associative array by key/value tuples.
insertInPlaceInserts into an existing array at a given position.
joinConcatenates a range of ranges into one array.
minimallyInitializedArrayReturns a new array of type T.
replaceReturns a new array with all occurrences of a certain subrange replaced.
replaceFirstReturns a new array with the first occurrence of a certain subrange replaced.
replaceInPlaceReplaces all occurrences of a certain subrange and puts the result into a given array.
replaceIntoReplaces all occurrences of a certain subrange and puts the result into an output range.
replaceLastReturns a new array with the last occurrence of a certain subrange replaced.
replaceSliceReturns a new array with a given slice replaced.
replicateCreates a new array out of several copies of an input array or range.
sameHeadChecks if the initial segments of two arrays refer to the same place in memory.
sameTailChecks if the final segments of two arrays refer to the same place in memory.
splitEagerly split a range or string into an array.
staticArrayCreates a new static array from given data.
uninitializedArrayReturns a new array of type T without initializing its elements.

Members

Functions

appender
Appender!A appender()
Appender!(E[]) appender(A array)

Convenience function that returns an Appender instance, optionally initialized with array.

appender
RefAppender!(E[]) appender(P arrayPtr)

Convenience function that returns a RefAppender instance initialized with arrayPtr. Don't use null for the array pointer, use the other version of appender instead.

array
ForeachType!Range[] array(Range r)
ForeachType!(typeof((*Range).init))[] array(Range r)

Allocates an array and initializes it with copies of the elements of range r.

array
CopyTypeQualifiers!(ElementType!String, dchar)[] array(String str)

Convert a narrow autodecoding string to an array type that fully supports random access. This is handled as a special case and always returns an array of dchar

assocArray
auto assocArray(Range r)
auto assocArray(Keys keys, Values values)

Returns a newly allocated associative array from a range of key/value tuples or from a range of keys and a range of values.

byPair
auto byPair(AA aa)

Construct a range iterating over an associative array by key/value tuples.

insertInPlace
void insertInPlace(T[] array, size_t pos, U stuff)

Inserts stuff (which must be an input range or any number of implicitly convertible items) in array at position pos.

join
ElementEncodingType!(ElementType!RoR)[] join(RoR ror, R sep)
ElementEncodingType!(ElementType!RoR)[] join(RoR ror, E sep)
ElementEncodingType!(ElementType!RoR)[] join(RoR ror)

Eagerly concatenates all of the ranges in ror together (with the GC) into one array using sep as the separator if present.

minimallyInitializedArray
auto minimallyInitializedArray(I sizes)

Returns a new array of type T allocated on the garbage collected heap.

overlap
CommonType!(T[], U[]) overlap(T[] a, U[] b)

Returns the overlapping portion, if any, of two arrays. Unlike equal, overlap only compares the pointers and lengths in the ranges, not the values referred by them. If r1 and r2 have an overlapping slice, returns that slice. Otherwise, returns the null slice.

popBack (from std.range.primitives)
void popBack(inout(T)[] a) via public import std.range.primitives : save, empty, popFront, popBack, front, back;

Implements the range interface primitive popBack for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.popBack is equivalent to popBack(array). For narrow strings, popFront automatically eliminates the last code point.

popFront (from std.range.primitives)
void popFront(inout(C)[] str) via public import std.range.primitives : save, empty, popFront, popBack, front, back;

Implements the range interface primitive popFront for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.popFront is equivalent to popFront(array). For narrow strings, popFront automatically advances to the next code point.

replace
E[] replace(E[] subject, R1 from, R2 to)

Replace occurrences of from with to in subject in a new array.

replace
E[] replace(E[] subject, R1 from, R2 to, size_t changed)

Replace occurrences of from with to in subject in a new array. changed counts how many replacements took place.

replace
T[] replace(T[] subject, size_t from, size_t to, Range stuff)

Replaces elements from array with indices ranging from from (inclusive) to to (exclusive) with the range stuff.

replaceFirst
E[] replaceFirst(E[] subject, R1 from, R2 to)

Replaces the first occurrence of from with to in subject.

replaceInPlace
void replaceInPlace(T[] array, size_t from, size_t to, Range stuff)

Replaces elements from array with indices ranging from from (inclusive) to to (exclusive) with the range stuff. Expands or shrinks the array as needed.

replaceInto
void replaceInto(Sink sink, E[] subject, R1 from, R2 to)

Replace occurrences of from with to in subject and output the result into sink.

replaceInto
void replaceInto(Sink sink, E[] subject, R1 from, R2 to, size_t changed)

Replace occurrences of from with to in subject and output the result into sink. changed counts how many replacements took place.

replaceLast
E[] replaceLast(E[] subject, R1 from, R2 to)

Replaces the last occurrence of from with to in subject.

replaceSlice
inout(T)[] replaceSlice(inout(T)[] s, T[] slice, T[] replacement)

Creates a new array such that the items in slice are replaced with the items in replacement. slice and replacement do not need to be the same length. The result will grow or shrink based on the items given.

replicate
ElementEncodingType!S[] replicate(S s, size_t n)
ElementType!S[] replicate(S s, size_t n)
sameHead
bool sameHead(T[] lhs, T[] rhs)

Returns whether the fronts of lhs and rhs both refer to the same place in memory, making one of the arrays a slice of the other which starts at index 0.

sameTail
bool sameTail(T[] lhs, T[] rhs)

Returns whether the backs of lhs and rhs both refer to the same place in memory, making one of the arrays a slice of the other which end at index $.

split
S[] split(S s)
auto split(Range range, Separator sep)
auto split(Range range)

Eagerly splits range into an array, using sep as the delimiter.

staticArray
T[n] staticArray(T[n] a)
U[n] staticArray(T[n] a)

Constructs a static array from a dynamic array whose length is known at compile-time. The element type can be inferred or specified explicitly:

staticArray
auto staticArray(T a)
auto staticArray(T a, size_t rangeLength)
auto staticArray()

Constructs a static array from a range. When a.length is not known at compile time, the number of elements must be given as a template argument (e.g. myrange.staticArray!2). Size and type can be combined, if the source range elements are implicitly convertible to the requested element type (eg: 2.iota.staticArray!(long[2])).

uninitializedArray
auto uninitializedArray(I sizes)

Returns a new array of type T allocated on the garbage collected heap without initializing its elements. This can be a useful optimization if every element will be immediately initialized. T may be a multidimensional array. In this case sizes may be specified for any number of dimensions from 0 to the number in T.

Properties

back (from std.range.primitives)
dchar back [@property getter] via public import std.range.primitives : save, empty, popFront, popBack, front, back;

Implements the range interface primitive back for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.back is equivalent to back(array). For narrow strings, back automatically returns the last code point as _a dchar.

empty (from std.range.primitives)
bool empty [@property getter] via public import std.range.primitives : save, empty, popFront, popBack, front, back;

Implements the range interface primitive empty for types that obey hasLength property and for narrow strings. Due to the fact that nonmember functions can be called with the first argument using the dot notation, a.empty is equivalent to empty(a).

front (from std.range.primitives)
dchar front [@property getter] via public import std.range.primitives : save, empty, popFront, popBack, front, back;

Implements the range interface primitive front for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.front is equivalent to front(array). For narrow strings, front automatically returns the first code point as _a dchar.

save (from std.range.primitives)
inout(T)[] save [@property getter] via public import std.range.primitives : save, empty, popFront, popBack, front, back;

Implements the range interface primitive save for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.save is equivalent to save(array). The function does not duplicate the content of the array, it simply returns its argument.

Structs

Appender
struct Appender(A)

Implements an output range that appends data to an array. This is recommended over array ~= data when appending many elements because it is more efficient. Appender maintains its own array metadata locally, so it can avoid the performance hit of looking up slice capacity for each append.

RefAppender
struct RefAppender(A)

A version of Appender that can update an array in-place. It forwards all calls to an underlying appender implementation. Any calls made to the appender also update the pointer to the original array passed in.

Meta