summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AK/Array.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/AK/Array.h b/AK/Array.h
index ee5cbd9dc5..d6f05d0a09 100644
--- a/AK/Array.h
+++ b/AK/Array.h
@@ -66,6 +66,26 @@ struct Array {
return Size;
}
+ constexpr T max() requires(requires(T x, T y) { x < y; })
+ {
+ static_assert(Size > 0, "No values to max() over");
+
+ T value = __data[0];
+ for (size_t i = 1; i < Size; ++i)
+ value = AK::max(__data[i], value);
+ return value;
+ }
+
+ constexpr T min() requires(requires(T x, T y) { x > y; })
+ {
+ static_assert(Size > 0, "No values to min() over");
+
+ T value = __data[0];
+ for (size_t i = 1; i < Size; ++i)
+ value = AK::min(__data[i], value);
+ return value;
+ }
+
T __data[Size];
};