mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Add min() and max() methods to Array<T, N>
...That are only defined when min() and max() are defined on the elements.
This commit is contained in:
parent
11306d7121
commit
b361793ad8
Notes:
sideshowbarker
2024-07-18 18:41:19 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/b361793ad8b Pull-request: https://github.com/SerenityOS/serenity/pull/6855
1 changed files with 20 additions and 0 deletions
20
AK/Array.h
20
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];
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue