From 07977ad94cb3334468dff576be57c742804c8ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Thu, 27 Jan 2022 12:53:52 +0100 Subject: [PATCH] AK: Introduce the ArrayLike concept The ArrayLike type concept focuses on array-like data accesses. This means the ability to randomly index, obtain size information, as well as being able to expose the storage pointer. The last two already have the standard APIs `size` and `data`, respectively. The ArrayLike concept should always be fulfilled by Vector, FixedArray and Array as the three main array-like types. C-style arrays themselves of course can't fulfil ArrayLike (which could be considered ironic), but as we don't use them much anyways this isn't a problem. --- AK/Concepts.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/AK/Concepts.h b/AK/Concepts.h index 5101f9d426..94136dfc11 100644 --- a/AK/Concepts.h +++ b/AK/Concepts.h @@ -41,6 +41,32 @@ concept HashCompatible = IsHashCompatible, Detail::Decay>; // FIXME: remove once Clang formats these properly. // clang-format off + +// Any indexable, sized, contiguous data structure. +template +concept ArrayLike = requires(ArrayT array, SizeT index) +{ + { + array[index] + } + -> SameAs&>; + + { + array.size() + } + -> SameAs; + + { + array.span() + } + -> SameAs>>; + + { + array.data() + } + -> SameAs*>; +}; + template concept VoidFunction = requires(Func func, Args... args) { @@ -77,6 +103,7 @@ concept IterableContainer = requires } using AK::Concepts::Arithmetic; +using AK::Concepts::ArrayLike; using AK::Concepts::Enum; using AK::Concepts::FloatingPoint; using AK::Concepts::Integral;