@@ -313,12 +313,16 @@ if (isBidirectionalRange!(Unqual!Range))
313
313
{
314
314
@property void front(ElementType! R val)
315
315
{
316
- source.back = val;
316
+ import std.algorithm.mutation : move;
317
+
318
+ source.back = move(val);
317
319
}
318
320
319
321
@property void back(ElementType! R val)
320
322
{
321
- source.front = val;
323
+ import std.algorithm.mutation : move;
324
+
325
+ source.front = move(val);
322
326
}
323
327
}
324
328
@@ -330,7 +334,9 @@ if (isBidirectionalRange!(Unqual!Range))
330
334
{
331
335
void opIndexAssign (ElementType! R val, size_t n)
332
336
{
333
- source[retroIndex(n)] = val;
337
+ import std.algorithm.mutation : move;
338
+
339
+ source[retroIndex(n)] = move(val);
334
340
}
335
341
}
336
342
@@ -474,6 +480,19 @@ pure @safe nothrow @nogc unittest
474
480
foreach (x; data.retro) {}
475
481
}
476
482
483
+ pure @safe nothrow unittest
484
+ {
485
+ import std.algorithm.comparison : equal;
486
+
487
+ static struct S {
488
+ int v;
489
+ @disable this (this );
490
+ }
491
+
492
+ immutable foo = [S(1 ), S(2 ), S(3 )];
493
+ auto r = retro(foo);
494
+ assert (equal(r, [S(3 ), S(2 ), S(1 )]));
495
+ }
477
496
478
497
/**
479
498
Iterates range `r` with stride `n`. If the range is a
585
604
{
586
605
@property void front(ElementType! R val)
587
606
{
588
- source.front = val;
607
+ import std.algorithm.mutation : move;
608
+
609
+ source.front = move(val);
589
610
}
590
611
}
591
612
@@ -864,6 +885,20 @@ pure @safe nothrow unittest
864
885
assert (equal(s, [1L , 4L , 7L ]));
865
886
}
866
887
888
+ pure @safe nothrow unittest
889
+ {
890
+ import std.algorithm.comparison : equal;
891
+
892
+ static struct S {
893
+ int v;
894
+ @disable this (this );
895
+ }
896
+
897
+ immutable foo = [S(1 ), S(2 ), S(3 ), S(4 ), S(5 )];
898
+ auto r = stride(foo, 3 );
899
+ assert (equal(r, [S(1 ), S(4 )]));
900
+ }
901
+
867
902
/**
868
903
Spans multiple ranges in sequence. The function `chain` takes any
869
904
number of ranges and returns a $(D Chain!(R1, R2,...)) object. The
@@ -1069,12 +1104,14 @@ if (Ranges.length > 0 &&
1069
1104
1070
1105
@property void front(RvalueElementType v)
1071
1106
{
1107
+ import std.algorithm.mutation : move;
1108
+
1072
1109
sw: switch (frontIndex)
1073
1110
{
1074
1111
static foreach (i; 0 .. R.length)
1075
1112
{
1076
1113
case i:
1077
- source[i].front = v ;
1114
+ source[i].front = move(v) ;
1078
1115
break sw;
1079
1116
}
1080
1117
@@ -1193,12 +1230,14 @@ if (Ranges.length > 0 &&
1193
1230
{
1194
1231
@property void back(RvalueElementType v)
1195
1232
{
1233
+ import std.algorithm.mutation : move;
1234
+
1196
1235
sw: switch (backIndex)
1197
1236
{
1198
1237
static foreach_reverse (i; 1 .. R.length + 1 )
1199
1238
{
1200
1239
case i:
1201
- source[i- 1 ].back = v ;
1240
+ source[i- 1 ].back = move(v) ;
1202
1241
break sw;
1203
1242
}
1204
1243
@@ -1304,6 +1343,8 @@ if (Ranges.length > 0 &&
1304
1343
static if (allSameType && allSatisfy! (hasAssignableElements, R))
1305
1344
void opIndexAssign (ElementType v, size_t index)
1306
1345
{
1346
+ import std.algorithm.mutation : move;
1347
+
1307
1348
sw: switch (frontIndex)
1308
1349
{
1309
1350
static foreach (i; 0 .. R.length)
@@ -1319,7 +1360,7 @@ if (Ranges.length > 0 &&
1319
1360
}
1320
1361
}
1321
1362
1322
- source[i][index] = v ;
1363
+ source[i][index] = move(v) ;
1323
1364
break sw;
1324
1365
}
1325
1366
@@ -1602,6 +1643,28 @@ pure @safe unittest
1602
1643
assert (equal(r, " foobar" ));
1603
1644
}
1604
1645
1646
+ pure @safe nothrow @nogc unittest
1647
+ {
1648
+ // support non-copyable items
1649
+
1650
+ static struct S {
1651
+ int v;
1652
+ @disable this (this );
1653
+ }
1654
+
1655
+ S[2 ] s0, s1;
1656
+ foreach (ref el; chain(s0[], s1[]))
1657
+ {
1658
+ int n = el.v;
1659
+ }
1660
+
1661
+ S[] s2, s3;
1662
+ foreach (ref el; chain(s2, s3))
1663
+ {
1664
+ int n = el.v;
1665
+ }
1666
+ }
1667
+
1605
1668
/**
1606
1669
Choose one of two ranges at runtime depending on a Boolean condition.
1607
1670
@@ -2035,6 +2098,23 @@ pure @safe unittest
2035
2098
auto chosen2 = chosen.save;
2036
2099
}
2037
2100
2101
+ pure @safe nothrow unittest
2102
+ {
2103
+ static struct S {
2104
+ int v;
2105
+ @disable this (this );
2106
+ }
2107
+
2108
+ auto a = [S(1 ), S(2 ), S(3 )];
2109
+ auto b = [S(4 ), S(5 ), S(6 )];
2110
+
2111
+ auto chosen = choose(true , a, b);
2112
+ assert (chosen.front.v == 1 );
2113
+
2114
+ auto chosen2 = choose(false , a, b);
2115
+ assert (chosen2.front.v == 4 );
2116
+ }
2117
+
2038
2118
/**
2039
2119
Choose one of multiple ranges at runtime.
2040
2120
@@ -2332,6 +2412,20 @@ pure @safe unittest
2332
2412
assert (equal(r.save, " fboaor" ));
2333
2413
assert (equal(r.save, " fboaor" ));
2334
2414
}
2415
+ pure @safe nothrow unittest
2416
+ {
2417
+ import std.algorithm.comparison : equal;
2418
+
2419
+ static struct S {
2420
+ int v;
2421
+ @disable this (this );
2422
+ }
2423
+
2424
+ S[] a = [ S(1 ), S(2 ) ];
2425
+ S[] b = [ S(10 ), S(20 ) ];
2426
+ auto r = roundRobin(a, b);
2427
+ assert (equal(r, [ S(1 ), S(10 ), S(2 ), S(20 ) ]));
2428
+ }
2335
2429
2336
2430
/**
2337
2431
Iterates a random-access range starting from a given point and
@@ -2904,10 +2998,12 @@ if (isInputRange!R)
2904
2998
{
2905
2999
@property auto ref front(ElementType! R v)
2906
3000
{
3001
+ import std.algorithm.mutation : move;
3002
+
2907
3003
assert (! empty,
2908
3004
" Attempting to assign to the front of an empty "
2909
3005
~ typeof (this ).stringof);
2910
- return _input.front = v ;
3006
+ return _input.front = move(v) ;
2911
3007
}
2912
3008
}
2913
3009
}
@@ -4139,7 +4235,9 @@ if (isForwardRange!R && !isInfinite!R)
4139
4235
// / ditto
4140
4236
@property void front(ElementType! R val)
4141
4237
{
4142
- _original[_index] = val;
4238
+ import std.algorithm.mutation : move;
4239
+
4240
+ _original[_index] = move(val);
4143
4241
}
4144
4242
}
4145
4243
@@ -4249,7 +4347,9 @@ if (isForwardRange!R && !isInfinite!R)
4249
4347
// / ditto
4250
4348
@property auto front(ElementType! R val)
4251
4349
{
4252
- return _current.front = val;
4350
+ import std.algorithm.mutation : move;
4351
+
4352
+ return _current.front = move(val);
4253
4353
}
4254
4354
}
4255
4355
@@ -7263,7 +7363,9 @@ struct FrontTransversal(Ror,
7263
7363
{
7264
7364
@property void front(ElementType val)
7265
7365
{
7266
- _input.front.front = val;
7366
+ import std.algorithm.mutation : move;
7367
+
7368
+ _input.front.front = move(val);
7267
7369
}
7268
7370
}
7269
7371
@@ -7320,7 +7422,9 @@ struct FrontTransversal(Ror,
7320
7422
{
7321
7423
@property void back(ElementType val)
7322
7424
{
7323
- _input.back.front = val;
7425
+ import std.algorithm.mutation : move;
7426
+
7427
+ _input.back.front = move(val);
7324
7428
}
7325
7429
}
7326
7430
}
@@ -7353,7 +7457,9 @@ struct FrontTransversal(Ror,
7353
7457
{
7354
7458
void opIndexAssign (ElementType val, size_t n)
7355
7459
{
7356
- _input[n].front = val;
7460
+ import std.algorithm.mutation : move;
7461
+
7462
+ _input[n].front = move(val);
7357
7463
}
7358
7464
}
7359
7465
mixin ImplementLength! _input;
0 commit comments