Function std.range.primitives.walkLength
This is a best-effort implementation of length for any kind of
range.
If , simply returns hasLength!Rangerange.length without
checking (when specified).
upTo
Otherwise, walks the range through its length and returns the number
of elements seen. Performes Ο(n) evaluations of range.empty
and range.popFront(), where n is the effective length of .
range
The parameter is useful to "cut the losses" in case
the interest is in seeing whether the upTorange has at least some number
of elements. If the parameter is specified, stops if upTo steps have been taken and returns upTo.
upTo
Infinite ranges are compatible, provided the parameter is
specified, in which case the implementation simply returns upToupTo.
Prototypes
auto walkLength(Range)( Range range ) if (isInputRange!Range && !isInfinite!Range); auto walkLength(Range)( Range range, size_t upTo ) if (isInputRange!Range);
Authors
Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.