Array.opSlice

  1. Range opSlice(size_t i, size_t j)
  2. ConstRange opSlice(size_t i, size_t j)
    struct Array(T)
    const @trusted
    opSlice
    (
    size_t i
    ,
    size_t j
    )

Parameters

i size_t

Slice start.

j size_t

Slice end.

Return Value

A range that iterates over elements of the container from index i up to (excluding) index j.

Precondition: i <= j && j <= length.

Examples

auto v = Array!int([1, 2, 3]);
auto r = v[];

assert(r.front == 1);
assert(r.back == 3);

r.popFront();
assert(r.front == 2);

r.popBack();
assert(r.back == 2);

assert(r.length == 1);
auto v = Array!int([1, 2, 3, 4]);
auto r = v[1 .. 4];
assert(r.length == 3);
assert(r[0] == 2);
assert(r[1] == 3);
assert(r[2] == 4);

r = v[0 .. 0];
assert(r.length == 0);

r = v[4 .. 4];
assert(r.length == 0);

Meta