Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 13390 - Be explicit about non-empty input and fail early #3001

Merged
merged 1 commit into from Mar 1, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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