Bug 6956 – std.algorithm.remove problem with SwapStrategy.unstable
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-11-15T16:38:00Z
Last change time
2012-05-25T10:14:13Z
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2011-11-15T16:38:31Z
This is a spin off of bug 6849. Problem partially found by Steven Schveighoffer.
import std.stdio, std.algorithm;
void main() {
int[] data1 = [10, 20, 30, 40];
writeln(remove(data1, 1));
writeln(data1);
int[] data2 = [10, 20, 30, 40];
writeln(remove!(SwapStrategy.unstable)(data2, 1));
writeln(data2);
}
Output, DMD 2.057head:
[10, 30, 40]
[10, 30, 40, 40]
[40, 20, 30]
[40, 20, 30, 40]
So with SwapStrategy.unstable it seems index 0 was removed, not index 1.
Expected output:
[10, 30, 40]
[10, 30, 40, 40]
[10, 40, 30]
[10, 40, 30, 40]
Comment #1 by lovelydear — 2012-04-22T03:10:47Z
*** This issue has been marked as a duplicate of issue 5224 ***
Comment #2 by andrej.mitrovich — 2012-05-25T08:37:54Z
I don't know if a bug is opened about this but it seems relevant:
import std.algorithm;
import std.stdio;
void main()
{
int[] a = [1, 2, 3];
a = a.remove(3);
writeln(a);
}
writes [1, 2]
This should throw since index 3 is out of bounds.
Comment #3 by bearophile_hugs — 2012-05-25T10:14:13Z
(In reply to comment #2)
> I don't know if a bug is opened about this but it seems relevant:
This is a closed (because it's a duplicate) bug, so I suggest you to copy that stuff elsewhere.