mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +03:00
Merge pull request #1011 from blackwhale/fix-multisort
fix issue 9160 multiSort constraint regression
This commit is contained in:
commit
194ca07803
1 changed files with 26 additions and 2 deletions
|
@ -7684,8 +7684,8 @@ private template validPredicates(E, less...) {
|
|||
enum validPredicates = true;
|
||||
else
|
||||
enum validPredicates =
|
||||
is(typeof(binaryFun!(less[0])(E.init, E.init)) == bool) &&
|
||||
validPredicates!(E, less[1 .. $]);
|
||||
is(typeof((E a, E b){ bool r = binaryFun!(less[0])(a, b); }))
|
||||
&& validPredicates!(E, less[1 .. $]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7766,6 +7766,30 @@ unittest
|
|||
assert(equal(pts3, pts2));
|
||||
}
|
||||
|
||||
unittest //issue 9160 (L-value only comparators)
|
||||
{
|
||||
static struct A
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
}
|
||||
|
||||
static bool byX(const ref A lhs, const ref A rhs)
|
||||
{
|
||||
return lhs.x < rhs.x;
|
||||
}
|
||||
|
||||
static bool byY(const ref A lhs, const ref A rhs)
|
||||
{
|
||||
return lhs.y < rhs.y;
|
||||
}
|
||||
|
||||
auto points = [ A(4, 1), A(2, 4)];
|
||||
multiSort!(byX, byY)(points);
|
||||
assert(points[0] == A(2, 4));
|
||||
assert(points[1] == A(4, 1));
|
||||
}
|
||||
|
||||
private size_t getPivot(alias less, Range)(Range r)
|
||||
{
|
||||
// This algorithm sorts the first, middle and last elements of r,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue