Vector.opIndex - multiple declarations

Function Vector.opIndex

Return slice of all elements (same as Vector.elements).

inout inout(Vector.ElementType)[] opIndex() pure nothrow @nogc @system;

The slice returned may be invalidated by further calls to other member functions that modify the object.

Examples

Vector!(int, 6) vec = Vector!(int, 6).build(1, 2, 3);

int[] slice = vec[];
assert(slice.length == vec.length);
assert(slice.ptr is vec.ptr);

vec.reserve(vec.capacity * 2);
assert(slice.length == vec.length);
// slice contains dangling pointer!

Function Vector.opIndex

Returns reference to element at specified location pos.

inout ref inout(Vector.ElementType) opIndex (
  const size_t pos
) pure nothrow @nogc scope @system;

Examples

auto vec = Vector!(int, 10).build(1, 2, 3);

assert(vec[1] == 2);