std.range.indexed - multiple declarations
- Function indexed
- Struct Indexed
Function indexed
This struct takes two ranges, and source, and creates a view
of indices as if its elements were reordered according to source.
indices may include indicesonly a subset of the elements of and
may also sourcerepeat 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.
Prototype
Indexed!(Source,Indices) indexed(Source, Indices)( Source source, Indices indices );
Example
import std.algorithm : 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, and source, and creates a view
of indices as if its elements were reordered according to source.
indices may include indicesonly a subset of the elements of and
may also sourcerepeat 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.
Properties
| Name | Type | Description |
|---|---|---|
front
[get]
|
ref |
Range primitives |
indices
[get]
|
Indices |
Returns the indices range.
|
source
[get]
|
Source |
Returns the source range.
|
Methods
| Name | Description |
|---|---|
popFront
|
Range primitives |
Example
import std.algorithm : 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, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.