Make permutations into forward range.

This commit is contained in:
james 2022-09-21 23:00:20 +02:00
parent 92a9d600d1
commit 370f14af6d

View file

@ -7909,7 +7909,13 @@ if (isRandomAccessRange!Range && hasLength!Range)
_indices = iota(size_t(r.length)).array;
_empty = r.length == 0;
}
private this(size_t[] indices, size_t[] state, Range r, bool empty_)
{
_indices = indices;
_state = state;
_r = r;
_empty = empty_;
}
/// Returns: `true` if the range is empty, `false` otherwise.
@property bool empty() const pure nothrow @safe @nogc
{
@ -7950,6 +7956,13 @@ if (isRandomAccessRange!Range && hasLength!Range)
next(2);
}
static if (isForwardRange!Range) {
///
auto save()
{
return typeof(this)(_indices.dup, _state.dup, _r.save, _empty);
}
}
}
///
@ -7965,3 +7978,15 @@ if (isRandomAccessRange!Range && hasLength!Range)
[1, 2, 0],
[2, 1, 0]]));
}
@safe unittest
{
import std.algorithm : equal;
import std.range : ElementType;
import std.array : array;
auto p = [1, 2, 3].permutations;
auto x = p.save.front;
p.popFront;
auto y = p.front;
assert(x != y);
}