The OpenD Programming Language

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.

stride
(
Range
)
(
Range r
,
size_t n
)

Parameters

r Range

the input range to stride over

n size_t

the number of elements to skip over

Return Value

Type: auto

At minimum, an input range. The resulting range will adopt the range primitives of the underlying range as long as std.range.primitives.hasLength is true.

Examples

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 ][]));
assert(stride(stride(a, 2), 3) == stride(a, 6));

Meta