www.digitalmars.com

D Programming Language 2.0

Last update Sun Apr 19 16:54:06 2009

std.array

bool empty(T)(in T[] a);
Implements the range interface primitive empty for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.empty is equivalent to empty(array).

Example:
void main()
{
    auto a = [ 1, 2, 3 ];
    assert(!a.empty);
    assert(a[3 .. $].empty);
}

void popFront(T)(ref T[] a);
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).

Example:
void main()
{
    int[] a = [ 1, 2, 3 ];
    a.popFront;
    assert(a == [ 2, 3 ]);
}

void popBack(T)(ref T[] a);
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).

Example:
void main()
{
    int[] a = [ 1, 2, 3 ];
    a.popBack;
    assert(a == [ 1, 2 ]);
}

typeof(A[0]) front(A)(A a);
void front(T)(T[] a, T v);
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).

Example:
void main()
{
    int[] a = [ 1, 2, 3 ];
    assert(a.front == 1);
}

T back(T)(T[] a);
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).

Example:
void main()
{
    int[] a = [ 1, 2, 3 ];
    assert(a.front == 1);
}

void put(T, E)(ref T[] a, E e);
Implements the range interface primitive put for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.put(e) is equivalent to put(array, e).

Example:
void main()
{
    int[] a = [ 1, 2, 3 ];
    int[] b = a;
    a.put(5);
    assert(a == [ 2, 3 ]);
    assert(b == [ 5, 2, 3 ]);
}

void insert(T, Range)(ref T[] array, size_t pos, Range stuff);
Inserts stuff in container at position pos.

void replace(T, Range)(ref T[] array, size_t from, size_t to, Range stuff);
Erases elements from array with indices ranging from from (inclusive) to to (exclusive).

Erases element from array at index from.

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

struct Appender(A : T[],T);
Implements an output range that appends data to an array. This is recommended over a ~= data because it is more efficient.

Example:
auto arr = new char[0];
auto app = appender(&arr);
string b = "abcdefg";
foreach (char c; b) app.put(c);
assert(app.data == "abcdefg");

int[] a = [ 1, 2 ];
auto app2 = appender(&a);
app2.put(3);
app2.put([ 4, 5, 6 ]);
assert(app2.data == [ 1, 2, 3, 4, 5, 6 ]);

this(T[]* p);
Initialize an Appender with a pointer to an existing array. The Appender object will append to this array. If null is passed (or the default constructor gets called), the Appender object will allocate and use a new array.

T[] data();
Returns the managed array.

const size_t capacity();
Returns the capacity of the array (the maximum number of elements the managed array can accommodate before triggering a reallocation).

alias AcceptedElementType;
An alias for the accepted type to be appended.

void put(AcceptedElementType item);
Appends one item to the managed array.

void put(AcceptedElementType[] items);
Appends another array to the managed array.

void put(in char c);
void put(in char[] cs);
void put(in wchar dc);
void put(in wchar[] dcs);
void put(in dchar dc);
void put(in dchar[] wcs);
In case the managed array has type char[], wchar[], or dchar[], all other character widths and arrays thereof are also accepted.

void clear();
Clears the managed array.

Appender!(E[]) appender(A : E[], E)(A* array = null);
Convenience function that returns an Appender!(T) object initialized with t.