1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:07:45 +00:00

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

View file

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