Skip to content

Commit

Permalink
Skip leading empty ranges in roundRobin
Browse files Browse the repository at this point in the history
Previously, roundRobin would always attempt to fetch its first element
from the first range passed to it, even if that range was empty.

Fixes bugzilla issue 24384.
  • Loading branch information
pbackus committed Feb 10, 2024
1 parent 37796e7 commit 720ac51
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 720ac51

Please sign in to comment.