digitalmars.D.bugs - [Issue 8341] New: topN(zip()) too?
- d-bugmail puremagic.com (42/42) Jul 03 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8341
http://d.puremagic.com/issues/show_bug.cgi?id=8341 Summary: topN(zip()) too? Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nobody puremagic.com ReportedBy: bearophile_hugs eml.cc 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 03 2012