Array.insertAfter

Inserts el before or after r.

  1. size_t insertAfter(Range r, R el)
    struct Array(T)
    size_t
    insertAfter
    (
    R
    )
    (,
    scope R el
    )
    if (
    !isInfinite!R &&
    isInputRange!R
    &&
    isImplicitlyConvertible!(ElementType!R, T)
    )
  2. size_t insertAfter(Range r, T[R] el)
  3. size_t insertAfter(Range r, R el)
  4. size_t insertBefore(Range r, R el)
  5. size_t insertBefore(Range r, T[R] el)
  6. size_t insertBefore(Range r, R el)

Parameters

R

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

r Range

Range originally obtained from this array.

el R

Value(s) should be inserted.

Return Value

Type: size_t

The number of elements inserted.

Precondition: r refers to a region of $(D_KEYWORD this).

Examples

Array!int v1;
v1.insertAfter(v1[], [2, 8]);
assert(v1[0] == 2);
assert(v1[1] == 8);
assert(v1.length == 2);

v1.insertAfter(v1[], [1, 2]);
assert(v1[0] == 2);
assert(v1[1] == 8);
assert(v1[2] == 1);
assert(v1[3] == 2);
assert(v1.length == 4);

v1.insertAfter(v1[0 .. 0], [1, 2]);
assert(v1[0] == 1);
assert(v1[1] == 2);
assert(v1[2] == 2);
assert(v1[3] == 8);
assert(v1[4] == 1);
assert(v1[5] == 2);
assert(v1.length == 6);

v1.insertAfter(v1[0 .. 4], 9);
assert(v1[0] == 1);
assert(v1[1] == 2);
assert(v1[2] == 2);
assert(v1[3] == 8);
assert(v1[4] == 9);
assert(v1[5] == 1);
assert(v1[6] == 2);
assert(v1.length == 7);
Array!int v1;
v1.insertBefore(v1[], [2, 8]);
assert(v1[0] == 2);
assert(v1[1] == 8);
assert(v1.length == 2);

v1.insertBefore(v1[], [1, 2]);
assert(v1[0] == 1);
assert(v1[1] == 2);
assert(v1[2] == 2);
assert(v1[3] == 8);
assert(v1.length == 4);

v1.insertBefore(v1[0 .. 1], [1, 2]);
assert(v1[0] == 1);
assert(v1[1] == 2);
assert(v1[2] == 1);
assert(v1[3] == 2);
assert(v1[4] == 2);
assert(v1[5] == 8);
assert(v1.length == 6);

v1.insertBefore(v1[2 .. $], 9);
assert(v1[0] == 1);
assert(v1[1] == 2);
assert(v1[2] == 9);
assert(v1[3] == 1);
assert(v1[4] == 2);
assert(v1[5] == 2);
assert(v1[6] == 8);
assert(v1.length == 7);

Meta