mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 23:20:29 +03:00
Make permutations into forward range.
This commit is contained in:
parent
92a9d600d1
commit
370f14af6d
1 changed files with 26 additions and 1 deletions
|
@ -7909,7 +7909,13 @@ if (isRandomAccessRange!Range && hasLength!Range)
|
||||||
_indices = iota(size_t(r.length)).array;
|
_indices = iota(size_t(r.length)).array;
|
||||||
_empty = r.length == 0;
|
_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.
|
/// Returns: `true` if the range is empty, `false` otherwise.
|
||||||
@property bool empty() const pure nothrow @safe @nogc
|
@property bool empty() const pure nothrow @safe @nogc
|
||||||
{
|
{
|
||||||
|
@ -7950,6 +7956,13 @@ if (isRandomAccessRange!Range && hasLength!Range)
|
||||||
|
|
||||||
next(2);
|
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],
|
[1, 2, 0],
|
||||||
[2, 1, 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);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue