Bug 8341 – topN(zip()) too?

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-07-03T13:16:11Z
Last change time
2018-03-12T13:07:49Z
Keywords
pull
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-07-03T13:16:11Z
This sorts (in reverse) the arrays a and b according to the (a,b) pairs: import std.stdio, std.algorithm, std.range; void main() { auto a = [10, 20, 30]; auto b = ["c", "b", "a"]; writeln(a, " ", b); sort!q{a > b}(zip(a, b)); // OK writeln(a, " ", b); } Output: [10, 20, 30] ["c", "b", "a"] [30, 20, 10] ["a", "b", "c"] But this code doesn't compile: import std.stdio, std.algorithm, std.range; void main() { auto a = [10, 20, 30]; auto b = ["c", "b", "a"]; writeln(a, " ", b); topN!q{a > b}(zip(a, b), 4); // error writeln(a, " ", b); } With the latest DMD2.060alpha it gives several errors like: algorithm.d(6826): Error: template std.algorithm.swap does not match any function template declaration I think topN doesn't need to ask more features than sort() to the range you give it. So maybe topN too should work here.
Comment #1 by greensunny12 — 2018-02-11T00:12:13Z
Comment #2 by github-bugzilla — 2018-03-12T13:07:49Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/ede44cbc63bb596085f2aa049ba924a481921bb7 Fix Issue 8341 - topN(zip()) doesn't work https://github.com/dlang/phobos/commit/78f7209c4a701749b1ed45c2da5bf1511309402f Merge pull request #6156 from wilzbach/fix-8341 Fix Issue 8341 - topN(zip()) doesn't work merged-on-behalf-of: Jack Stouffer <[email protected]>