AK: Array can tell its inner type

Array should be able to tell the type of the elements it contains.
This commit is contained in:
Arne Elster 2021-12-06 18:51:00 +01:00 committed by Andreas Kling
parent 107872db8e
commit 6a0cac7cdb
Notes: sideshowbarker 2024-07-17 18:13:39 +09:00

View file

@ -13,6 +13,8 @@ namespace AK {
template<typename T, size_t Size>
struct Array {
using ValueType = T;
[[nodiscard]] constexpr T const* data() const { return __data; }
[[nodiscard]] constexpr T* data() { return __data; }
@ -66,7 +68,7 @@ struct Array {
return Size;
}
[[nodiscard]] constexpr T max() requires(requires(T x, T y) { x < y; })
[[nodiscard]] constexpr T max() const requires(requires(T x, T y) { x < y; })
{
static_assert(Size > 0, "No values to max() over");
@ -76,7 +78,7 @@ struct Array {
return value;
}
[[nodiscard]] constexpr T min() requires(requires(T x, T y) { x > y; })
[[nodiscard]] constexpr T min() const requires(requires(T x, T y) { x > y; })
{
static_assert(Size > 0, "No values to min() over");