[Issue 8341] New: topN(zip()) too?
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jul 3 13:16:14 PDT 2012
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 at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2012-07-03 13:16:11 PDT ---
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: -------
More information about the Digitalmars-d-bugs
mailing list