Array.insert

Inserts the elements of an input range, or a variable number of items, at the given pos.

If no allocator was provided when the array was created, the GCAllocator.std.experimental.allocator.gc_allocator. will be used. If Stuff defines length, Array will use it to reserve the necessary amount of memory.

  1. size_t insert(size_t pos, Stuff stuff)
  2. size_t insert(size_t pos, Stuff[] stuff)
    struct Array(T)
    size_t
    insert
    (
    Stuff
    )
    (
    size_t pos
    ,
    Stuff[] stuff...
    )
    if (
    isImplicitlyConvertible!(Stuff, T)
    )

Parameters

pos size_t

a positive integer

stuff Stuff[]

an input range of elements that are implitictly convertible to T; a variable number of items either in the form of a list or as a built-in array

Return Value

Type: size_t

the number of elements inserted

Complexity: O(max(length, pos + m)), where m is the number of elements in the range.

Examples

import std.algorithm.comparison : equal;

Array!int a;
assert(a.empty);

size_t pos = 0;
pos += a.insert(pos, 1);
pos += a.insert(pos, [2, 3]);
assert(equal(a, [1, 2, 3]));

Meta