mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 09:00:22 +03:00
Fix Issue 20751 - SortedRange with ref predicate parameters fails
isTwoWayCompatible should accept functions with ref parameters.
This commit is contained in:
parent
9844c34196
commit
54dbc0668c
2 changed files with 24 additions and 11 deletions
|
@ -2067,6 +2067,17 @@ if (((ss == SwapStrategy.unstable && (hasSwappableElements!Range ||
|
|||
r.sort();
|
||||
assert(proxySwapCalled);
|
||||
}
|
||||
|
||||
// https://issues.dlang.org/show_bug.cgi?id=20751
|
||||
{
|
||||
static bool refPred(ref int a, ref int b)
|
||||
{
|
||||
return a < b;
|
||||
}
|
||||
|
||||
auto sortedArr = [5,4,3,2,1].sort!refPred;
|
||||
sortedArr.equalRange(3);
|
||||
}
|
||||
}
|
||||
|
||||
private void quickSortImpl(alias less, Range)(Range r, size_t depth)
|
||||
|
|
|
@ -10540,21 +10540,19 @@ version (none)
|
|||
Returns true if `fn` accepts variables of type T1 and T2 in any order.
|
||||
The following code should compile:
|
||||
---
|
||||
T1 foo();
|
||||
T2 bar();
|
||||
|
||||
fn(foo(), bar());
|
||||
fn(bar(), foo());
|
||||
(ref T1 a, ref T2 b)
|
||||
{
|
||||
fn(a, b);
|
||||
fn(b, a);
|
||||
}
|
||||
---
|
||||
*/
|
||||
template isTwoWayCompatible(alias fn, T1, T2)
|
||||
{
|
||||
enum isTwoWayCompatible = is(typeof( (){
|
||||
T1 foo();
|
||||
T2 bar();
|
||||
|
||||
cast(void) fn(foo(), bar());
|
||||
cast(void) fn(bar(), foo());
|
||||
enum isTwoWayCompatible = is(typeof((ref T1 a, ref T2 b)
|
||||
{
|
||||
cast(void) fn(a, b);
|
||||
cast(void) fn(b, a);
|
||||
}
|
||||
));
|
||||
}
|
||||
|
@ -10568,6 +10566,10 @@ template isTwoWayCompatible(alias fn, T1, T2)
|
|||
static assert(isTwoWayCompatible!(func1, int, int));
|
||||
static assert(isTwoWayCompatible!(func1, short, int));
|
||||
static assert(!isTwoWayCompatible!(func2, int, float));
|
||||
|
||||
void func3(ref int a, ref int b);
|
||||
static assert( isTwoWayCompatible!(func3, int, int));
|
||||
static assert(!isTwoWayCompatible!(func3, short, int));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue