Skip to content

Commit f879790

Browse files
authored
Merge pull request dlang#10829 from ntrel/drop-not-ref
[std.range docs] drop and dropOne may not mutate the range
2 parents 85c6e3a + bdf6907 commit f879790

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

std/range/package.d

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3881,9 +3881,11 @@ pure @safe nothrow @nogc unittest
38813881
}
38823882

38833883
/++
3884-
Convenience function which calls
3884+
`drop` is a convenience function which calls
38853885
$(REF popFrontN, std, range, primitives)`(range, n)` and returns `range`.
3886-
`drop` makes it easier to pop elements from a range
3886+
Unlike `popFrontN`, the range argument is passed by copy, not by `ref`.
3887+
3888+
`drop` makes it easier to pop elements from a range rvalue
38873889
and then pass it to another function within a single expression,
38883890
whereas `popFrontN` would require multiple statements.
38893891
@@ -3916,7 +3918,10 @@ if (isInputRange!R)
39163918
{
39173919
import std.algorithm.comparison : equal;
39183920

3919-
assert([0, 2, 1, 5, 0, 3].drop(3) == [5, 0, 3]);
3921+
auto a = [0, 2, 1, 5, 0, 3];
3922+
assert(a.drop(3) == [5, 0, 3]);
3923+
assert(a.length == 6); // original unchanged
3924+
39203925
assert("hello world".drop(6) == "world");
39213926
assert("hello world".drop(50).empty);
39223927
assert("hello world".take(6).drop(3).equal("lo "));
@@ -3993,8 +3998,8 @@ if (isBidirectionalRange!R)
39933998
`range` with `n` elements dropped
39943999
39954000
See_Also:
3996-
$(REF popFrontExcatly, std, range, primitives),
3997-
$(REF popBackExcatly, std, range, primitives)
4001+
$(REF popFrontExactly, std, range, primitives),
4002+
$(REF popBackExactly, std, range, primitives)
39984003
+/
39994004
R dropExactly(R)(R range, size_t n)
40004005
if (isInputRange!R)
@@ -4030,9 +4035,11 @@ if (isBidirectionalRange!R)
40304035
}
40314036

40324037
/++
4033-
Convenience function which calls
4034-
`range.popFront()` and returns `range`. `dropOne`
4035-
makes it easier to pop an element from a range
4038+
`dropOne` is a convenience function which calls
4039+
`range.popFront()` and returns `range`.
4040+
Unlike `popFront`, the range argument is passed by copy, not by `ref`.
4041+
4042+
`dropOne` makes it easier to pop an element from a range rvalue
40364043
and then pass it to another function within a single expression,
40374044
whereas `popFront` would require multiple statements.
40384045

0 commit comments

Comments
 (0)