AK: Introduce Indexable concept

This was dearly missing and can be used in many existing templates.
This commit is contained in:
kleines Filmröllchen 2022-04-21 10:41:27 +02:00 committed by Linus Groh
parent af1c26f05b
commit bbb256e8b5
Notes: sideshowbarker 2024-07-17 03:22:24 +09:00

View File

@ -79,6 +79,16 @@ concept ArrayLike = requires(ArrayT array, SizeT index)
-> SameAs<RemoveReference<ContainedT>*>;
};
// Any indexable data structure.
template<typename ArrayT, typename ContainedT, typename SizeT = size_t>
concept Indexable = requires(ArrayT array, SizeT index)
{
{
array[index]
}
-> OneOf<RemoveReference<ContainedT>&, RemoveReference<ContainedT>>;
};
template<typename Func, typename... Args>
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;