Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

Merged
merged 2 commits into from almost 2 years ago

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 May 27, 2012
David Simcha dsimcha closed this May 27, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 15 additions and 2 deletions. Show diff stats Hide diff stats

  1. 17  std/algorithm.d
17  std/algorithm.d
@@ -847,7 +847,7 @@ assert(a == [ 5, 5, 5, 5 ]);
847 847
 ----
848 848
  */
849 849
 void fill(Range, Value)(Range range, Value filler)
850  
-if (isForwardRange!Range && is(typeof(range.front = filler)))
  850
+if (isInputRange!Range && is(typeof(range.front = filler)))
851 851
 {
852 852
     alias ElementType!Range T;
853 853
     static if (hasElaborateCopyConstructor!T || !isDynamicArray!Range)
@@ -894,6 +894,13 @@ unittest
894 894
     void fun1() { foreach (i; 0 .. 1000) fill(a, 6); }
895 895
     //void fun2() { foreach (i; 0 .. 1000) fill2(a, 6); }
896 896
     //writeln(benchmark!(fun0, fun1, fun2)(10000));
  897
+    // fill should accept InputRange
  898
+    alias DummyRange!(ReturnBy.Reference, Length.No, RangeType.Input) InputRange;
  899
+    enum filler = uint.max;
  900
+    InputRange range;
  901
+    fill(range,filler);
  902
+    foreach(value;range.arr)
  903
+    	assert(value == filler);
897 904
 }
898 905
 
899 906
 /**
@@ -910,7 +917,7 @@ assert(a == [ 8, 9, 8, 9, 8 ]);
910 917
 ----
911 918
  */
912 919
 void fill(Range1, Range2)(Range1 range, Range2 filler)
913  
-if (isForwardRange!Range1 && isForwardRange!Range2
  920
+if (isInputRange!Range1 && isForwardRange!Range2
914 921
         && is(typeof(Range1.init.front = Range2.init.front)))
915 922
 {
916 923
     enforce(!filler.empty);
@@ -930,6 +937,12 @@ unittest
930 937
     int[] b = [1, 2];
931 938
     fill(a, b);
932 939
     assert(a == [ 1, 2, 1, 2, 1 ]);
  940
+    // fill should accept InputRange
  941
+    alias DummyRange!(ReturnBy.Reference, Length.No, RangeType.Input) InputRange;
  942
+    InputRange range;
  943
+    fill(range,[1,2]);
  944
+    foreach(i,value;range.arr)
  945
+    	assert(value == (i%2==0?1:2));
933 946
 }
934 947
 
935 948
 /**
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.