-
-
Notifications
You must be signed in to change notification settings - Fork 703
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6154 from wilzbach/fix-12086
Fix Issue 12086 - std.algorithm.remove + range of indices produces wrong results merged-on-behalf-of: Nathan Sashihara <n8sh@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
172 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
`std.algorithm.mutation.remove` now only accepts integral values or pair of integral values as offset | ||
|
||
Previously, without being stated in the documentation, | ||
$(REF remove, std,algorithm) used to accept any values as `offset`. | ||
This behavior was very error-prone: | ||
|
||
--- | ||
import std.algorithm, std.stdio; | ||
[0, 1, 2, 3, 4].remove(1, 3).writeln; // 0, 2, 4 -- correct | ||
[0, 1, 2, 3, 4].remove([1, 3]).writeln; // 0, 3, 4 -- incorrect | ||
--- | ||
|
||
With this release, using arrays as individual elements is no longer valid. | ||
$(REF tuple, std,typecons) can be used to explicitly indicate that a range | ||
from `start` to `stop` (non-enclosing) should be removed: | ||
|
||
--- | ||
import std.algorithm, std.stdio, std.typecons; | ||
[0, 1, 2, 3, 4].remove(tuple(1, 3)).writeln; // 0, 3, 4 | ||
--- | ||
|
||
However, only 2-tuples are allowed to avoid this un-intuitive scenario: | ||
|
||
--- | ||
import std.algorithm, std.stdio, std.typecons; | ||
[0, 1, 2, 3, 4].remove(tuple(1, 3, 4)).writeln; // 0, 4? | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters