Merge pull request #1011 from blackwhale/fix-multisort

fix issue 9160 multiSort constraint regression
This commit is contained in:
Hara Kenji 2012-12-16 17:34:09 -08:00
commit 194ca07803

View file

@ -7684,8 +7684,8 @@ private template validPredicates(E, less...) {
enum validPredicates = true; enum validPredicates = true;
else else
enum validPredicates = enum validPredicates =
is(typeof(binaryFun!(less[0])(E.init, E.init)) == bool) && is(typeof((E a, E b){ bool r = binaryFun!(less[0])(a, b); }))
validPredicates!(E, less[1 .. $]); && validPredicates!(E, less[1 .. $]);
} }
/** /**
@ -7766,6 +7766,30 @@ unittest
assert(equal(pts3, pts2)); 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) private size_t getPivot(alias less, Range)(Range r)
{ {
// This algorithm sorts the first, middle and last elements of r, // This algorithm sorts the first, middle and last elements of r,