Skip to content

Commit

Permalink
Fix Issue 13390 - Be explicit about non-empty input and fail early
Browse files Browse the repository at this point in the history
Add unittest
  • Loading branch information
kuettler committed Feb 17, 2015
1 parent 320a7b4 commit 568cd18
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions std/range/package.d
Expand Up @@ -2473,6 +2473,8 @@ random access and also offers a constructor taking an initial position
$(D index). $(D Cycle) works with static arrays in addition to ranges,
mostly for performance reasons.
Note: The input range must not be empty.
Tip: This is a great way to implement simple circular buffers.
*/
struct Cycle(R)
Expand Down Expand Up @@ -2698,6 +2700,7 @@ nothrow:
Cycle!R cycle(R)(R input)
if (isForwardRange!R && !isInfinite!R)
{
assert(!input.empty);
return Cycle!R(input);
}

Expand All @@ -2713,6 +2716,7 @@ Cycle!R cycle(R)(R input)
Cycle!R cycle(R)(R input, size_t index = 0)
if (isRandomAccessRange!R && !isInfinite!R)
{
assert(!input.empty);
return Cycle!R(input, index);
}

Expand Down Expand Up @@ -2890,6 +2894,14 @@ unittest //10845
auto a = recurrence!q{a[n - 1] ~ a[n - 2]}("1", "0");
}

// Issue 13390
unittest
{
import std.exception;
import core.exception : AssertError;
assertThrown!AssertError(cycle([0, 1, 2][0..0]));
}

private alias lengthType(R) = typeof(R.init.length.init);

/**
Expand Down

0 comments on commit 568cd18

Please sign in to comment.