Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions std/range/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ if (Ranges.length > 0 &&
// We do this separately to avoid invoking `empty` needlessly.
// While not recommended, a range may depend on side effects of
// `empty` call.
foreach (i, ref v; input) if (!v.empty)
foreach (i, ref v; source) if (!v.empty)
{
frontIndex = i;
static if (bidirectional) backIndex = i+1;
Expand All @@ -1056,7 +1056,7 @@ if (Ranges.length > 0 &&
static foreach_reverse (i; 1 .. R.length + 1)
{
if (i <= frontIndex + 1) return;
if (!input[i-1].empty)
if (!source[i-1].empty)
{
backIndex = i;
return;
Expand Down Expand Up @@ -11019,6 +11019,23 @@ auto only()()
static assert(!__traits(compiles, () { r3[0] = 789; }));
}

// https://github.com/dlang/phobos/issues/10561
@safe unittest
{
static struct Range
{
private int i;

enum bool empty = false;
int front() => i;
void popFront() { ++i; }
}
import std.algorithm;

assert(Range().take(10).filter!"a>8".chain(only(100)).equal([9,100]));
assert((new Range()).take(10).filter!"a>8".chain(only(100)).equal([9,100]));
}

/**
Iterate over `range` with an attached index variable.

Expand Down
Loading