Bug 16996 – std.algorithm.remove with SwapStrategy.unstable removes more entries

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-12-20T21:47:00Z
Last change time
2017-01-16T23:26:20Z
Keywords
pull
Assigned to
nobody
Creator
greeenify

Comments

Comment #0 by greeenify — 2016-12-20T21:47:57Z
I assume the following is a bug: auto a = [ 0, 1, 2, 3, 4, 5 ]; assert(remove!(SwapStrategy.stable)(a, tuple(1, 4)) == [0, 4, 5]); a = [ 0, 1, 2, 3, 4, 5 ]; assert(remove!(SwapStrategy.unstable)(a, tuple(1, 4)) == [0]); or at least this behavior should be properly documented.
Comment #1 by safety0ff.bugz — 2016-12-20T22:15:31Z
Passing a tuple or array of offset is interpreted as (start, end) pairs. See third example: https://dlang.org/phobos/std_algorithm_mutation.html#.remove I agree that it is error prone and could use more visible documentation, see also #12086.
Comment #2 by safety0ff.bugz — 2016-12-20T22:17:15Z
Sorry, I didn't read properly.
Comment #3 by safety0ff.bugz — 2016-12-20T22:34:06Z
Right, it looks like a bug. It should be [0,5,4] or [0,4,5], the former being what the documentation suggests the result will be.
Comment #4 by safety0ff.bugz — 2016-12-21T01:21:50Z
Comment #5 by github-bugzilla — 2016-12-29T05:53:25Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/424aec1159f045948f896e921dded5b8ef5f00fa Fix Issue 16996 - std.algorithm.remove with SwapStrategy.unstable removes more entries https://github.com/dlang/phobos/commit/3c0b47ab513034fb29abbf849873c87e81264813 Merge pull request #4979 from WalterWaldron/fix16996 Fix Issue 16996 - std.algorithm.remove with SwapStrategy.unstable rem…
Comment #6 by github-bugzilla — 2017-01-07T03:03:24Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/424aec1159f045948f896e921dded5b8ef5f00fa Fix Issue 16996 - std.algorithm.remove with SwapStrategy.unstable removes more entries https://github.com/dlang/phobos/commit/3c0b47ab513034fb29abbf849873c87e81264813 Merge pull request #4979 from WalterWaldron/fix16996
Comment #7 by github-bugzilla — 2017-01-16T23:26:20Z
Commits pushed to newCTFE at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/424aec1159f045948f896e921dded5b8ef5f00fa Fix Issue 16996 - std.algorithm.remove with SwapStrategy.unstable removes more entries https://github.com/dlang/phobos/commit/3c0b47ab513034fb29abbf849873c87e81264813 Merge pull request #4979 from WalterWaldron/fix16996