aboutsummaryrefslogtreecommitdiff
path: root/libphobos/src/std/algorithm/searching.d
diff options
context:
space:
mode:
Diffstat (limited to 'libphobos/src/std/algorithm/searching.d')
-rw-r--r--libphobos/src/std/algorithm/searching.d82
1 files changed, 82 insertions, 0 deletions
diff --git a/libphobos/src/std/algorithm/searching.d b/libphobos/src/std/algorithm/searching.d
index 42a9df5..b7119d2 100644
--- a/libphobos/src/std/algorithm/searching.d
+++ b/libphobos/src/std/algorithm/searching.d
@@ -3735,6 +3735,47 @@ if (isInputRange!Range && !isInfinite!Range &&
assert(arr.minElement!"a.val".val == 0);
}
+// https://issues.dlang.org/show_bug.cgi?id=24827
+@safe unittest
+{
+ static struct S
+ {
+ int i;
+ bool destroyed;
+
+ this(int i) @safe
+ {
+ this.i = i;
+ }
+
+ ~this() @safe
+ {
+ destroyed = true;
+ }
+
+ bool opEquals()(auto ref S rhs)
+ {
+ return this.i == rhs.i;
+ }
+
+ int opCmp()(auto ref S rhs)
+ {
+ if (this.i < rhs.i)
+ return -1;
+
+ return this.i == rhs.i ? 0 : 1;
+ }
+
+ @safe invariant
+ {
+ assert(!destroyed);
+ }
+ }
+
+ auto arr = [S(19), S(2), S(145), S(7)];
+ assert(minElement(arr) == S(2));
+}
+
/**
Iterates the passed range and returns the maximal element.
A custom mapping function can be passed to `map`.
@@ -3888,6 +3929,47 @@ if (isInputRange!Range && !isInfinite!Range &&
assert(arr[0].getI == 2);
}
+// https://issues.dlang.org/show_bug.cgi?id=24827
+@safe unittest
+{
+ static struct S
+ {
+ int i;
+ bool destroyed;
+
+ this(int i) @safe
+ {
+ this.i = i;
+ }
+
+ ~this() @safe
+ {
+ destroyed = true;
+ }
+
+ bool opEquals()(auto ref S rhs)
+ {
+ return this.i == rhs.i;
+ }
+
+ int opCmp()(auto ref S rhs)
+ {
+ if (this.i < rhs.i)
+ return -1;
+
+ return this.i == rhs.i ? 0 : 1;
+ }
+
+ @safe invariant
+ {
+ assert(!destroyed);
+ }
+ }
+
+ auto arr = [S(19), S(2), S(145), S(7)];
+ assert(maxElement(arr) == S(145));
+}
+
// minPos
/**
Computes a subrange of `range` starting at the first occurrence of `range`'s