Bug 5049 – std.algortihm.bringToFront() returns wrong value
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-13T00:32:00Z
Last change time
2010-10-15T10:58:08Z
Assigned to
rsinfu
Creator
rsinfu
Comments
Comment #0 by rsinfu — 2010-10-13T00:32:46Z
The doc states that bringToFront() returns the number of elements brought to the front, but it actually returns the number of swaps done:
--------------------
import std.algorithm, std.stdio;
void main()
{
auto r = [4, 5, 6, 7, 0, 1, 2, 3];
foreach (k; 0 .. r.length)
writeln(bringToFront(r, r[k .. $]));
}
--------------------
% dmd -run test.d
0
7
6
7
4
7
6
7
--------------------
The output should be "0 7 6 5 4 3 2 1".
Comment #1 by andrei — 2010-10-13T17:54:57Z
Good catch. Shin, feel free to take this over if you plan to fix it.