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