View source code
Display the source code in std/range.d from which this page was generated on
github.
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.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.range.stride
Iterates range
with r
stride
. If the range is a
random-access range, moves by indexing into the range; otherwise,
moves by successive calls to n
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
to be 0.
n
Prototype
auto stride(Range)( Range r, size_t n ) if (isInputRange!(Unqual!Range));
Example
import std.algorithm : equal; int[] a = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]; assert(equal(stride(a, 3), [ 1, 4, 7, 10 ][])); assert(stride(stride(a, 2), 3) == stride(a, 6));
Authors
Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.