From 83854606412fdf01e8c1dcc41113a304e832a8a6 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 28 Jul 2025 17:07:27 +0100 Subject: [PATCH 1/5] [std.range] `drop` and `dropOne` do not mutate the range --- std/range/package.d | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/std/range/package.d b/std/range/package.d index 82580599a7d..d3a34ed5d26 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -3881,9 +3881,12 @@ pure @safe nothrow @nogc unittest } /++ - Convenience function which calls + `drop` is a convenience function which calls $(REF popFrontN, std, range, primitives)`(range, n)` and returns `range`. - `drop` makes it easier to pop elements from a range + Unlike `popFrontN`, the range argument is not passed by `ref`, so it will + not be mutated. + + `drop` makes it easier to pop elements from a range rvalue and then pass it to another function within a single expression, whereas `popFrontN` would require multiple statements. @@ -3916,7 +3919,10 @@ if (isInputRange!R) { import std.algorithm.comparison : equal; - assert([0, 2, 1, 5, 0, 3].drop(3) == [5, 0, 3]); + auto a = [0, 2, 1, 5, 0, 3]; + assert(a.drop(3) == [5, 0, 3]); + assert(a.length == 6); // original unchanged + assert("hello world".drop(6) == "world"); assert("hello world".drop(50).empty); assert("hello world".take(6).drop(3).equal("lo ")); @@ -4030,9 +4036,12 @@ if (isBidirectionalRange!R) } /++ - Convenience function which calls - `range.popFront()` and returns `range`. `dropOne` - makes it easier to pop an element from a range + `dropOne` is a convenience function which calls + `range.popFront()` and returns `range`. + Unlike `popFront`, the range argument is not passed by `ref`, so it will + not be mutated. + + `dropOne` makes it easier to pop an element from a range rvalue and then pass it to another function within a single expression, whereas `popFront` would require multiple statements. From 152046c14ce6e286fed309c4582bd6fc7fc00b5b Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 28 Jul 2025 17:07:57 +0100 Subject: [PATCH 2/5] Fix link typos --- std/range/package.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/std/range/package.d b/std/range/package.d index d3a34ed5d26..4a7217cab10 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -3999,8 +3999,8 @@ if (isBidirectionalRange!R) `range` with `n` elements dropped See_Also: - $(REF popFrontExcatly, std, range, primitives), - $(REF popBackExcatly, std, range, primitives) + $(REF popFrontExactly, std, range, primitives), + $(REF popBackExactly, std, range, primitives) +/ R dropExactly(R)(R range, size_t n) if (isInputRange!R) From 5ab6a95f23d273ec68189ddc2dd27d70a43d66cc Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 28 Jul 2025 17:53:51 +0100 Subject: [PATCH 3/5] range *may* not be mutated --- std/range/package.d | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/std/range/package.d b/std/range/package.d index 4a7217cab10..2a2957d89f8 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -3883,8 +3883,8 @@ pure @safe nothrow @nogc unittest /++ `drop` is a convenience function which calls $(REF popFrontN, std, range, primitives)`(range, n)` and returns `range`. - Unlike `popFrontN`, the range argument is not passed by `ref`, so it will - not be mutated. + Unlike `popFrontN`, the range argument is not passed by `ref`, so + it may not be mutated. `drop` makes it easier to pop elements from a range rvalue and then pass it to another function within a single expression, @@ -4038,8 +4038,8 @@ if (isBidirectionalRange!R) /++ `dropOne` is a convenience function which calls `range.popFront()` and returns `range`. - Unlike `popFront`, the range argument is not passed by `ref`, so it will - not be mutated. + Unlike `popFront`, the range argument is not passed by `ref`, so + it may not be mutated. `dropOne` makes it easier to pop an element from a range rvalue and then pass it to another function within a single expression, From 74c2beea2ab2c427df00dd32e8c421c25086f741 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 1 Aug 2025 10:44:42 +0100 Subject: [PATCH 4/5] wording: source range may not get popped --- std/range/package.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/std/range/package.d b/std/range/package.d index 2a2957d89f8..8d0967ad265 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -3884,7 +3884,7 @@ pure @safe nothrow @nogc unittest `drop` is a convenience function which calls $(REF popFrontN, std, range, primitives)`(range, n)` and returns `range`. Unlike `popFrontN`, the range argument is not passed by `ref`, so - it may not be mutated. + the source range may not get popped. `drop` makes it easier to pop elements from a range rvalue and then pass it to another function within a single expression, @@ -4039,7 +4039,7 @@ if (isBidirectionalRange!R) `dropOne` is a convenience function which calls `range.popFront()` and returns `range`. Unlike `popFront`, the range argument is not passed by `ref`, so - it may not be mutated. + the source range may not get popped. `dropOne` makes it easier to pop an element from a range rvalue and then pass it to another function within a single expression, From bdf690781146a2aba5349b2f070af43772b57895 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 13 Aug 2025 10:38:32 +0100 Subject: [PATCH 5/5] 'passed by copy, not by ref' --- std/range/package.d | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/std/range/package.d b/std/range/package.d index 8d0967ad265..4620b98071e 100644 --- a/std/range/package.d +++ b/std/range/package.d @@ -3883,8 +3883,7 @@ pure @safe nothrow @nogc unittest /++ `drop` is a convenience function which calls $(REF popFrontN, std, range, primitives)`(range, n)` and returns `range`. - Unlike `popFrontN`, the range argument is not passed by `ref`, so - the source range may not get popped. + Unlike `popFrontN`, the range argument is passed by copy, not by `ref`. `drop` makes it easier to pop elements from a range rvalue and then pass it to another function within a single expression, @@ -4038,8 +4037,7 @@ if (isBidirectionalRange!R) /++ `dropOne` is a convenience function which calls `range.popFront()` and returns `range`. - Unlike `popFront`, the range argument is not passed by `ref`, so - the source range may not get popped. + Unlike `popFront`, the range argument is passed by copy, not by `ref`. `dropOne` makes it easier to pop an element from a range rvalue and then pass it to another function within a single expression,