Fix topN(Range, Range) disrespect of its predicate

This commit is contained in:
Infiltrator 2015-12-08 17:57:01 +11:00 committed by Tim Sviridov
parent 3f9a33f91d
commit d70356e019

View file

@ -2301,7 +2301,7 @@ auto topN(alias less = "a < b",
static assert(ss == SwapStrategy.unstable,
"Stable topN not yet implemented");
auto heap = BinaryHeap!Range1(r1);
auto heap = BinaryHeap!(Range1, less)(r1);
for (; !r2.empty; r2.popFront())
{
heap.conditionalInsert(r2.front);
@ -2326,6 +2326,16 @@ unittest
assert(t == [ 0, 1, 2, 2, 3 ]);
}
// bug 15420
unittest
{
int[] a = [ 5, 7, 2, 6, 7 ];
int[] b = [ 2, 1, 5, 6, 7, 3, 0 ];
topN!"a > b"(a, b);
sort!"a > b"(a);
assert(a == [ 7, 7, 7, 6, 6 ]);
}
/**
Copies the top $(D n) elements of the input range $(D source) into the
random-access range $(D target), where $(D n =