The OpenD Programming Language

Indexed

This struct takes two ranges, source and indices, and creates a view of source as if its elements were reordered according to indices. indices may include only a subset of the elements of source and may also repeat elements.

Source must be a random access range. The returned range will be bidirectional or random-access if Indices is bidirectional or random-access, respectively.

Members

Functions

moveAt
auto moveAt(size_t index)
moveBack
auto moveBack()
moveFront
auto moveFront()
opIndex
auto ref opIndex(size_t index)
opIndexAssign
auto opIndexAssign(ElementType!Source newVal, size_t index)
opSlice
typeof(this) opSlice(size_t a, size_t b)

Range primitives

physicalIndex
size_t physicalIndex(size_t logicalIndex)

Returns the physical index into the source range corresponding to a given logical index. This is useful, for example, when indexing an Indexed without adding another layer of indirection.

popBack
void popBack()
popFront
void popFront()
back
auto ref back [@property getter]
ElementType!Source back [@property setter]
empty
bool empty [@property getter]

Range primitives

Properties

front
auto ref front [@property getter]
ElementType!Source front [@property setter]

Range primitives

indices
Indices indices [@property getter]

Returns the indices range.

save
typeof(this) save [@property getter]

Range primitives

source
Source source [@property getter]

Returns the source range.

Examples

import std.algorithm.comparison : equal;
auto source = [1, 2, 3, 4, 5];
auto indices = [4, 3, 1, 2, 0, 4];
auto ind = indexed(source, indices);
assert(equal(ind, [5, 4, 2, 3, 1, 5]));
assert(equal(retro(ind), [5, 1, 3, 2, 4, 5]));

Meta