D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5049 - std.algortihm.bringToFront() returns wrong value
Summary: std.algortihm.bringToFront() returns wrong value
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: Shin Fujishiro
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-13 00:32 UTC by Shin Fujishiro
Modified: 2010-10-15 10:58 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Shin Fujishiro 2010-10-13 00:32:46 UTC
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 Andrei Alexandrescu 2010-10-13 17:54:57 UTC
Good catch. Shin, feel free to take this over if you plan to fix it.
Comment 2 Shin Fujishiro 2010-10-14 11:04:28 UTC
All right, I'll fix it.
Comment 3 Shin Fujishiro 2010-10-15 10:58:08 UTC
Fixed in the svn trunk r2103.