Changeset 1695
- Timestamp:
- 06/29/10 02:58:31 (14 years ago)
- Files:
-
- trunk/phobos/std/range.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/phobos/std/range.d
r1694 r1695 2142 2142 int[] a = [ 1, 2, 3 ]; 2143 2143 float[] b = [ 1., 2, 3 ]; 2144 2144 foreach (e; zip(a, b)) 2145 2145 { 2146 2146 assert(e.at!(0) == e.at!(1)); 2147 2147 } 2148 2148 auto z = zip(a, b); 2149 2149 swap(z.front(), z.back()); 2150 2150 //@@@BUG@@@ 2151 2151 //sort!("a.at!(0) < b.at!(0)")(zip(a, b)); 2152 2153 // Horribly broken. See bugs 4402, 3123 2154 // foreach(DummyType1; AllDummyRanges) { 2155 // DummyType1 d1; 2156 // foreach(DummyType2; AllDummyRanges) { 2157 // DummyType2 d2; 2158 // auto r = zip(d1, d2); 2159 // 2160 // assert(equal(map!"a.at!0"(r), [1,2,3,4,5,6,7,8,9,10])); 2161 // assert(equal(map!"a.at!1"(r), [1,2,3,4,5,6,7,8,9,10])); 2162 // } 2163 // } 2152 2164 } 2153 2165 2154 2166 /** 2155 2167 Creates a mathematical sequence given the initial values and a 2156 2168 recurrence function that computes the popFront value from the existing 2157 2169 values. The sequence comes in the form of an infinite forward 2158 2170 range. The type $(D Recurrence) itself is seldom used directly; most 2159 2171 often, recurrences are obtained by calling the function $(D 2160 2172 recurrence). 2161 2173 … … 2676 2688 2677 2689 /// Ditto 2678 2690 FrontTransversal!(RangeOfRanges, opt) frontTransversal( 2679 2691 TransverseOptions opt = TransverseOptions.assumeJagged, 2680 2692 RangeOfRanges) 2681 2693 (RangeOfRanges rr) 2682 2694 { 2683 2695 return typeof(return)(rr); 2684 2696 } 2685 2697 2698 unittest { 2699 foreach(DummyType; AllDummyRanges) { 2700 static if(DummyType.r == ReturnBy.Reference) { // Bug 4403 2701 auto dummies = [DummyType.init, DummyType.init]; 2702 auto ft = frontTransversal(dummies); 2703 assert(equal(ft, [1, 1])); 2704 } 2705 } 2706 } 2707 2686 2708 /** 2687 2709 Given a range of ranges, iterate transversally through the the $(D 2688 2710 n)th element of each of the enclosed ranges. All elements of the 2689 2711 enclosing range must offer random access. 2690 2712 2691 2713 Example: 2692 2714 ---- 2693 2715 int[][] x = new int[][2]; 2694 2716 x[0] = [1, 2]; 2695 2717 x[1] = [3, 4]; … … 2814 2836 unittest 2815 2837 { 2816 2838 int[][] x = new int[][2]; 2817 2839 x[0] = [ 1, 2 ]; 2818 2840 x[1] = [3, 4]; 2819 2841 auto ror = transversal(x, 1); 2820 2842 auto witness = [ 2, 4 ]; 2821 2843 uint i; 2822 2844 foreach (e; ror) assert(e == witness[i++]); 2823 2845 assert(i == 2); 2846 2847 // Test w/o ref return. Doesn't work due to bug 4404. 2848 // alias DummyRange!(ReturnBy.Value, Length.Yes, RangeType.Random) D; 2849 // auto drs = [D.init, D.init]; 2850 // foreach(num; 0..10) { 2851 // auto t = transversal(drs, num); 2852 // assert(equal(t, [num + 1, num + 1])); 2853 // } 2824 2854 } 2825 2855 2826 2856 struct Transposed(RangeOfRanges) 2827 2857 { 2828 2858 alias typeof(map!"a.front"(RangeOfRanges.init)) ElementType; 2829 2859 2830 2860 this(RangeOfRanges input) 2831 2861 { 2832 2862 this._input = input; 2833 2863 }
