@@ -771,6 +771,23 @@ private struct MapResult(alias fun, Range)
771771 assert (dd.length == 4 );
772772}
773773
774+ // Verify fix for: https://issues.dlang.org/show_bug.cgi?id=16034
775+ @safe unittest
776+ {
777+ struct One
778+ {
779+ int entry = 1 ;
780+ @disable this (this );
781+ }
782+
783+ One[] ones = [One(), One()];
784+
785+ import std.algorithm.comparison : equal;
786+
787+ assert (ones.map! ` a.entry + 1` .equal([2 , 2 ]));
788+ }
789+
790+
774791@safe unittest
775792{
776793 import std.algorithm.comparison : equal;
@@ -1798,7 +1815,7 @@ if (isInputRange!R)
17981815 assert (equal(g3, [ tuple(1 , 2u ), tuple(2 , 2u ) ]));
17991816
18001817 interface I {}
1801- class C : I { override size_t toHash() const nothrow @safe { return 0 ; } }
1818+ static class C : I { override size_t toHash() const nothrow @safe { return 0 ; } }
18021819 const C[] a4 = [new const C()];
18031820 auto g4 = a4.group! " a is b" ;
18041821 assert (g4.front[1 ] == 1 );
@@ -2255,25 +2272,26 @@ if (isForwardRange!Range)
22552272 import std.algorithm.comparison : equal;
22562273
22572274 size_t popCount = 0 ;
2258- class RefFwdRange
2275+ static class RefFwdRange
22592276 {
22602277 int [] impl;
2278+ size_t * pcount;
22612279
22622280 @safe nothrow :
22632281
2264- this (int [] data) { impl = data; }
2282+ this (int [] data, size_t * pcount ) { impl = data; this .pcount = pcount ; }
22652283 @property bool empty() { return impl.empty; }
22662284 @property auto ref front() { return impl.front; }
22672285 void popFront ()
22682286 {
22692287 impl.popFront();
2270- popCount ++ ;
2288+ ( * pcount) ++ ;
22712289 }
2272- @property auto save() { return new RefFwdRange(impl); }
2290+ @property auto save() { return new RefFwdRange(impl, pcount ); }
22732291 }
22742292 static assert (isForwardRange! RefFwdRange);
22752293
2276- auto testdata = new RefFwdRange([1 , 3 , 5 , 2 , 4 , 7 , 6 , 8 , 9 ]);
2294+ auto testdata = new RefFwdRange([1 , 3 , 5 , 2 , 4 , 7 , 6 , 8 , 9 ], &popCount );
22772295 auto groups = testdata.chunkBy! ((a,b) => (a % 2 ) == (b % 2 ));
22782296 auto outerSave1 = groups.save;
22792297
@@ -6058,7 +6076,7 @@ if (is(typeof(binaryFun!pred(r.front, s.front)) : bool)
60586076 import std.algorithm.comparison : equal;
60596077
60606078 // Test by-reference separator
6061- class RefSep {
6079+ static class RefSep {
60626080 @safe :
60636081 string _impl;
60646082 this (string s) { _impl = s; }
@@ -7908,7 +7926,13 @@ if (isRandomAccessRange!Range && hasLength!Range)
79087926 _indices = iota(size_t (r.length)).array;
79097927 _empty = r.length == 0 ;
79107928 }
7911-
7929+ private this (size_t [] indices, size_t [] state, Range r, bool empty_)
7930+ {
7931+ _indices = indices;
7932+ _state = state;
7933+ _r = r;
7934+ _empty = empty_;
7935+ }
79127936 // / Returns: `true` if the range is empty, `false` otherwise.
79137937 @property bool empty() const pure nothrow @safe @nogc
79147938 {
@@ -7949,6 +7973,11 @@ if (isRandomAccessRange!Range && hasLength!Range)
79497973
79507974 next(2 );
79517975 }
7976+ // / Returns: an independent copy of the permutations range.
7977+ auto save ()
7978+ {
7979+ return typeof (this )(_indices.dup , _state.dup , _r.save, _empty);
7980+ }
79527981}
79537982
79547983// /
@@ -7964,3 +7993,15 @@ if (isRandomAccessRange!Range && hasLength!Range)
79647993 [1 , 2 , 0 ],
79657994 [2 , 1 , 0 ]]));
79667995}
7996+
7997+ @safe unittest
7998+ {
7999+ import std.algorithm.comparison : equal;
8000+ import std.range : ElementType;
8001+ import std.array : array;
8002+ auto p = [1 , 2 , 3 ].permutations;
8003+ auto x = p.save.front;
8004+ p.popFront;
8005+ auto y = p.front;
8006+ assert (x != y);
8007+ }
0 commit comments