Bug 10173 – std.algorithm.remove should throw exception on wrong ordering of indices to remove
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-05-26T05:20:23Z
Last change time
2019-12-14T08:16:17Z
Keywords
pull
Assigned to
Andrei Alexandrescu
Creator
Dmitry Olshansky
Comments
Comment #0 by dmitry.olsh — 2013-05-26T05:20:23Z
The following passage from documentation is not respected:
"""
Multiple indices can be passed into remove. In that case, elements at the respective indices are all removed. The indices must be passed in increasing order, otherwise an exception occurs.
"""
The following test asserts in remove for all 4 cases (r1-r4):
unittest
{
import std.algorithm, std.range, std.stdio, std.typecons;
int[] test = iota(0, 10).array;
auto r1 = remove!(SwapStrategy.stable)(test, tuple(2, 4), tuple(1, 3));
auto r2 = remove!(SwapStrategy.unstable)(test, tuple(2, 4), tuple(1, 3));
auto r3 = remove!(SwapStrategy.stable)(test, 2, 4, 1, 3);
auto r4 = remove!(SwapStrategy.unstable)(test, 2, 4, 1, 3);
}
Better yet remove may as well do reordering and merging of overlaping regions.
Depending on how this is solved it could become an enhancement request.
But at the very least Docs and code must be in sync.