From 365557ddd7e2124c13ef48c286498ed3f58ea8d8 Mon Sep 17 00:00:00 2001 From: Jonne Ransijn Date: Sat, 16 Nov 2024 23:52:11 +0100 Subject: [PATCH] AK: Add `IterableContainerOf` concept This concept not only checks that the given type is iterable, but it also checks that the iterated value is of the expected type. --- AK/Concepts.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/AK/Concepts.h b/AK/Concepts.h index 51f1644f986..e6a7be77c44 100644 --- a/AK/Concepts.h +++ b/AK/Concepts.h @@ -122,6 +122,13 @@ concept IterableContainer = requires { } -> IteratorPairWith().end())>; }; +template +concept IterableContainerOf = IterableContainer && requires { + { + *declval().begin() + } -> SameAs; +}; + template concept FallibleFunction = requires(Func&& func, Args&&... args) { func(forward(args)...).is_error(); @@ -173,6 +180,7 @@ using AK::Concepts::Fundamental; using AK::Concepts::Indexable; using AK::Concepts::Integral; using AK::Concepts::IterableContainer; +using AK::Concepts::IterableContainerOf; using AK::Concepts::IteratorFunction; using AK::Concepts::IteratorPairWith; using AK::Concepts::OneOf;