Array.insertBack

Inserts the el into the array.

  1. size_t insertBack(R el)
  2. size_t insertBack(R el)
  3. size_t insertBack(R el)
    struct Array(T)
    size_t
    insertBack
    (
    R
    )
    (
    scope R el
    )
    if (
    !isInfinite!R &&
    isInputRange!R
    &&
    isImplicitlyConvertible!(ElementType!R, T)
    )
  4. size_t insertBack(T[R] el)
  5. alias insert = insertBack

Parameters

R

Type of the inserted value(s) (single value, range or static array).

el R

Value(s) should be inserted.

Return Value

Type: size_t

The number of elements inserted.

Examples

struct TestRange
{
    int counter = 6;

    int front()
    {
        return counter;
    }

    void popFront()
    {
        counter -= 2;
    }

    bool empty()
    {
        return counter == 0;
    }
}

Array!int v1;

assert(v1.insertBack(5) == 1);
assert(v1.length == 1);
assert(v1.capacity == 1);
assert(v1.back == 5);

assert(v1.insertBack(TestRange()) == 3);
assert(v1.length == 4);
assert(v1.capacity == 4);
assert(v1[0] == 5 && v1[1] == 6 && v1[2] == 4 && v1[3] == 2);

assert(v1.insertBack([34, 234]) == 2);
assert(v1.length == 6);
assert(v1.capacity == 6);
assert(v1[4] == 34 && v1[5] == 234);

Meta