Skip to content

Commit

Permalink
Merge pull request #8911 from pbackus/fix-24384
Browse files Browse the repository at this point in the history
Skip leading empty ranges in roundRobin
  • Loading branch information
pbackus authored Feb 14, 2024
2 parents 42b8c65 + 720ac51 commit bbbdfd5
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion std/range/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -2427,7 +2427,14 @@ if (Rs.length > 1 && allSatisfy!(isInputRange, staticMap!(Unqual, Rs)))
}
}

return Result(rs, 0);
size_t firstNonEmpty = size_t.max;
static foreach (i; 0 .. Rs.length)
{
if (firstNonEmpty == size_t.max && !rs[i].empty)
firstNonEmpty = i;
}

return Result(rs, firstNonEmpty);
}

///
Expand Down Expand Up @@ -2489,6 +2496,14 @@ pure @safe nothrow unittest
assert(equal(r, [ S(1), S(10), S(2), S(20) ]));
}

// https://issues.dlang.org/show_bug.cgi?id=24384
@safe unittest
{
auto r = roundRobin("", "a");
assert(!r.empty);
auto e = r.front;
}

/**
Iterates a random-access range starting from a given point and
progressively extending left and right from that point. If no initial
Expand Down

0 comments on commit bbbdfd5

Please sign in to comment.