diff options
Diffstat (limited to 'AK/Array.h')
-rw-r--r-- | AK/Array.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/AK/Array.h b/AK/Array.h index 3bb11998a3..52ffa5560e 100644 --- a/AK/Array.h +++ b/AK/Array.h @@ -7,6 +7,7 @@ #pragma once #include <AK/Iterator.h> +#include <AK/Optional.h> #include <AK/Span.h> #include <AK/StdLibExtras.h> #include <AK/TypedTransfer.h> @@ -119,6 +120,20 @@ struct Array { return value; } + bool contains_slow(T const& value) const + { + return first_index_of(value).has_value(); + } + + Optional<size_t> first_index_of(T const& value) const + { + for (size_t i = 0; i < Size; ++i) { + if (__data[i] == value) + return i; + } + return {}; + } + Conditional<Size == 0, Detail::EmptyArrayStorage<T>, T[Size]> __data; }; |