View source code
Display the source code in std/range/package.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.range.stride
Iterates range r
with stride n
. If the range is a
random-access range, moves by indexing into the range; otherwise,
moves by successive calls to popFront
. Applying stride twice to
the same range results in a stride with a step that is the
product of the two applications. It is an error for n
to be 0.
auto auto stride(Range)
(
Range r,
size_t n
)
if (isInputRange!(Unqual!Range));
Parameters
Name | Description |
---|---|
r | the input range to stride over |
n | the number of elements to skip over |
Returns
At minimum, an input range. The resulting range will adopt the
range primitives of the underlying range as long as
hasLength
is true
.
Example
import std .algorithm .comparison : equal;
int[] a = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ];
assert(equal(stride(a, 3), [ 1, 4, 7, 10 ][]));
writeln(stride(stride(a, 2), 3)); // stride(a, 6)
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.
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.