From bbb256e8b50e38dd8b68f39827de5bad8c1d4a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Thu, 21 Apr 2022 10:41:27 +0200 Subject: [PATCH] AK: Introduce Indexable concept This was dearly missing and can be used in many existing templates. --- AK/Concepts.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/AK/Concepts.h b/AK/Concepts.h index 8b193d5127..6368310bfa 100644 --- a/AK/Concepts.h +++ b/AK/Concepts.h @@ -79,6 +79,16 @@ concept ArrayLike = requires(ArrayT array, SizeT index) -> SameAs*>; }; +// Any indexable data structure. +template +concept Indexable = requires(ArrayT array, SizeT index) +{ + { + array[index] + } + -> OneOf&, RemoveReference>; +}; + template concept VoidFunction = requires(Func func, Args... args) { @@ -130,6 +140,7 @@ using AK::Concepts::Enum; using AK::Concepts::FallibleFunction; using AK::Concepts::FloatingPoint; using AK::Concepts::Fundamental; +using AK::Concepts::Indexable; using AK::Concepts::Integral; using AK::Concepts::IterableContainer; using AK::Concepts::IteratorFunction;