R is a forward range. A forward range is an
r that can save "checkpoints" by saving
to another value of type
R. Notable examples of input ranges that
are not forward ranges are file/socket ranges; copying such a
range will not save the position in the stream, and they most likely
reuse an internal buffer as the entire stream does not sit in
memory. Subsequently, advancing either the original or the copy will
advance the stream, so the copies are not independent.
enum isForwardRange(R) = isInputRange!R && is(ReturnType!((R r) => r
.save) == R);
The following code should compile for any forward range.
Saving a range is not duplicating it; in the example above,
r2 still refer to the same underlying data. They just
navigate that data independently.
The semantics of a forward range (not checkable during compilation)
are the same as for an input range, with the additional requirement
that backtracking must be possible by saving a copy of the range
save and using it later.
The header of
std for tutorials on ranges.
static assert(!isForwardRange!(int)); static assert( isForwardRange!(int)); static assert( isForwardRange!(inout(int)));