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.

  1. struct Indexed(Source, Indices)
  2. Indexed!(Source, Indices) indexed(Source source, Indices indices)
    Indexed!(Source, Indices)
    indexed
    (
    Source
    Indices
    )
    (
    Source source
    ,
    Indices indices
    )

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

Suggestion Box / Bug Report