mirror of
https://github.com/dlang/phobos.git
synced 2025-05-01 07:30:33 +03:00
[Static if] replace overload constraints with static if (sorting.d)
This commit is contained in:
parent
78acf07136
commit
59508c4949
1 changed files with 30 additions and 42 deletions
|
@ -3748,16 +3748,18 @@ void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
|
||||||
(Range r, RangeIndex index, SortOutput sorted = No.sortOutput)
|
(Range r, RangeIndex index, SortOutput sorted = No.sortOutput)
|
||||||
if (isRandomAccessRange!Range &&
|
if (isRandomAccessRange!Range &&
|
||||||
isRandomAccessRange!RangeIndex &&
|
isRandomAccessRange!RangeIndex &&
|
||||||
hasAssignableElements!RangeIndex &&
|
hasAssignableElements!RangeIndex)
|
||||||
isIntegral!(ElementType!(RangeIndex)))
|
|
||||||
{
|
{
|
||||||
static assert(ss == SwapStrategy.unstable,
|
static assert(ss == SwapStrategy.unstable,
|
||||||
"Stable swap strategy not implemented yet.");
|
"Stable swap strategy not implemented yet.");
|
||||||
|
|
||||||
import std.container : BinaryHeap;
|
import std.container.binaryheap : BinaryHeap;
|
||||||
|
if (index.empty) return;
|
||||||
|
|
||||||
|
static if (isIntegral!(ElementType!(RangeIndex)))
|
||||||
|
{
|
||||||
import std.exception : enforce;
|
import std.exception : enforce;
|
||||||
|
|
||||||
if (index.empty) return;
|
|
||||||
enforce(ElementType!(RangeIndex).max >= index.length,
|
enforce(ElementType!(RangeIndex).max >= index.length,
|
||||||
"Index type too small");
|
"Index type too small");
|
||||||
bool indirectLess(ElementType!(RangeIndex) a, ElementType!(RangeIndex) b)
|
bool indirectLess(ElementType!(RangeIndex) a, ElementType!(RangeIndex) b)
|
||||||
|
@ -3769,27 +3771,10 @@ if (isRandomAccessRange!Range &&
|
||||||
{
|
{
|
||||||
heap.conditionalInsert(cast(ElementType!RangeIndex) i);
|
heap.conditionalInsert(cast(ElementType!RangeIndex) i);
|
||||||
}
|
}
|
||||||
if (sorted == Yes.sortOutput)
|
|
||||||
{
|
|
||||||
while (!heap.empty) heap.removeFront();
|
|
||||||
}
|
}
|
||||||
}
|
else static if (is(ElementType!(RangeIndex) == ElementType!(Range)*))
|
||||||
|
{
|
||||||
/// ditto
|
|
||||||
void topNIndex(alias less = "a < b", SwapStrategy ss = SwapStrategy.unstable,
|
|
||||||
Range, RangeIndex)
|
|
||||||
(Range r, RangeIndex index, SortOutput sorted = No.sortOutput)
|
|
||||||
if (isRandomAccessRange!Range &&
|
|
||||||
isRandomAccessRange!RangeIndex &&
|
|
||||||
hasAssignableElements!RangeIndex &&
|
|
||||||
is(ElementType!(RangeIndex) == ElementType!(Range)*))
|
|
||||||
{
|
|
||||||
static assert(ss == SwapStrategy.unstable,
|
|
||||||
"Stable swap strategy not implemented yet.");
|
|
||||||
|
|
||||||
import std.container : BinaryHeap;
|
|
||||||
|
|
||||||
if (index.empty) return;
|
|
||||||
static bool indirectLess(const ElementType!(RangeIndex) a,
|
static bool indirectLess(const ElementType!(RangeIndex) a,
|
||||||
const ElementType!(RangeIndex) b)
|
const ElementType!(RangeIndex) b)
|
||||||
{
|
{
|
||||||
|
@ -3800,6 +3785,9 @@ if (isRandomAccessRange!Range &&
|
||||||
{
|
{
|
||||||
heap.conditionalInsert(&r[i]);
|
heap.conditionalInsert(&r[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else static assert(0, "Invalid ElementType");
|
||||||
|
|
||||||
if (sorted == Yes.sortOutput)
|
if (sorted == Yes.sortOutput)
|
||||||
{
|
{
|
||||||
while (!heap.empty) heap.removeFront();
|
while (!heap.empty) heap.removeFront();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue