Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue 8112 - std.algorithm.fill must accept InputRange #588

Merged
merged 2 commits into from

3 participants

Guillaume Chatelet David Nadlinger David Simcha
David Nadlinger
Collaborator

The code change is fine, although you might be able to use DummyRange (see the top of range.d) for the tests.

Also, please prefix the commit message with »Issue 8112« so that the commit is picked up by GitHub's Bugzilla hook.

Guillaume Chatelet

Thx @klickverbot . I'm new to pull requests and D contribution : ) Should be fine with the last commit.

David Simcha dsimcha merged commit b1e1fa6 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 17, 2012
  1. Guillaume Chatelet
Commits on May 26, 2012
  1. Guillaume Chatelet
This page is out of date. Refresh to see the latest.
Showing with 15 additions and 2 deletions.
  1. +15 −2 std/algorithm.d
17 std/algorithm.d
View
@@ -847,7 +847,7 @@ assert(a == [ 5, 5, 5, 5 ]);
----
*/
void fill(Range, Value)(Range range, Value filler)
-if (isForwardRange!Range && is(typeof(range.front = filler)))
+if (isInputRange!Range && is(typeof(range.front = filler)))
{
alias ElementType!Range T;
static if (hasElaborateCopyConstructor!T || !isDynamicArray!Range)
@@ -894,6 +894,13 @@ unittest
void fun1() { foreach (i; 0 .. 1000) fill(a, 6); }
//void fun2() { foreach (i; 0 .. 1000) fill2(a, 6); }
//writeln(benchmark!(fun0, fun1, fun2)(10000));
+ // fill should accept InputRange
+ alias DummyRange!(ReturnBy.Reference, Length.No, RangeType.Input) InputRange;
+ enum filler = uint.max;
+ InputRange range;
+ fill(range,filler);
+ foreach(value;range.arr)
+ assert(value == filler);
}
/**
@@ -910,7 +917,7 @@ assert(a == [ 8, 9, 8, 9, 8 ]);
----
*/
void fill(Range1, Range2)(Range1 range, Range2 filler)
-if (isForwardRange!Range1 && isForwardRange!Range2
+if (isInputRange!Range1 && isForwardRange!Range2
&& is(typeof(Range1.init.front = Range2.init.front)))
{
enforce(!filler.empty);
@@ -930,6 +937,12 @@ unittest
int[] b = [1, 2];
fill(a, b);
assert(a == [ 1, 2, 1, 2, 1 ]);
+ // fill should accept InputRange
+ alias DummyRange!(ReturnBy.Reference, Length.No, RangeType.Input) InputRange;
+ InputRange range;
+ fill(range,[1,2]);
+ foreach(i,value;range.arr)
+ assert(value == (i%2==0?1:2));
}
/**
Something went wrong with that request. Please try again.