std.range.Indexed/indexed
- multiple declarations
Function 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.
Example
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]));
Struct 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.
struct Indexed(Source, Indices)
if (isRandomAccessRange!Source && isInputRange!Indices && is(typeof(Source .init[ElementType!Indices .init])));
Source
must be a random access range. The returned range will be
bidirectional or random-access if Indices
is bidirectional or
random-access, respectively.
Properties
Name | Type | Description |
---|---|---|
back [get, set]
|
auto | Range primitives |
front [get, set]
|
auto | Range primitives |
indices [get]
|
Indices | Returns the indices range. |
save [get]
|
typeof(this) | Range primitives |
source [get]
|
Source | Returns the source range. |
Methods
Name | Description |
---|---|
moveAt
(index)
|
Range primitives |
moveBack
()
|
Range primitives |
moveFront
()
|
Range primitives |
opIndex
(index)
|
Range primitives |
opIndexAssign
(newVal, index)
|
Range primitives |
opSlice
(a, b)
|
Range primitives |
physicalIndex
(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
()
|
Range primitives |
popFront
()
|
Range primitives |
Example
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]));
Authors
Andrei Alexandrescu, David Simcha, Jonathan M Davis, and Jack Stouffer. Credit for some of the ideas in building this module goes to Leonardo Maffi.