Check for sortedness must not use == (#7928)

Check for sortedness must not use `==`
merged-on-behalf-of: Razvan Nitu <RazvanN7@users.noreply.github.com>
This commit is contained in:
Arne 2021-04-14 17:58:11 +02:00 committed by GitHub
parent 64398c058f
commit 8c42ec9d8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1171,8 +1171,7 @@ if (Rs.length >= 2 &&
{ {
if (!source[i].empty) if (!source[i].empty)
{ {
assert(previousFront == source[i].front || assert(!comp(source[i].front, previousFront),
comp(previousFront, source[i].front),
"Input " ~ i.stringof ~ " is unsorted"); // @nogc "Input " ~ i.stringof ~ " is unsorted"); // @nogc
} }
} }
@ -1238,8 +1237,7 @@ if (Rs.length >= 2 &&
{ {
if (!source[i].empty) if (!source[i].empty)
{ {
assert(previousBack == source[i].back || assert(!comp(previousBack, source[i].back),
comp(source[i].back, previousBack),
"Input " ~ i.stringof ~ " is unsorted"); // @nogc "Input " ~ i.stringof ~ " is unsorted"); // @nogc
} }
} }
@ -1445,6 +1443,37 @@ if (Rs.length >= 2 &&
assert(m.empty); assert(m.empty);
} }
// Issue 21810: Check for sortedness must not use `==`
@nogc @safe pure nothrow unittest
{
import std.algorithm.comparison : equal;
import std.typecons : tuple;
static immutable a = [
tuple(1, 1),
tuple(3, 1),
tuple(3, 2),
tuple(5, 1),
];
static immutable b = [
tuple(2, 1),
tuple(3, 1),
tuple(4, 1),
tuple(4, 2),
];
static immutable r = [
tuple(1, 1),
tuple(2, 1),
tuple(3, 1),
tuple(3, 2),
tuple(3, 1),
tuple(4, 1),
tuple(4, 2),
tuple(5, 1),
];
assert(merge!"a[0] < b[0]"(a, b).equal(r));
}
private template validPredicates(E, less...) private template validPredicates(E, less...)
{ {
static if (less.length == 0) static if (less.length == 0)