Function Array.opSlice

Array.Range opSlice (
  size_t i,
  size_t j
) @trusted;

Array.ConstRange opSlice (
  size_t i,
  size_t j
) const @trusted;

Parameters

NameDescription
i Slice start.
j Slice end.

Returns

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

Precondition

i <= j && j <= length.

Example

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);

Example

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);