mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-21 18:15:58 +00:00
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.
This commit is contained in:
parent
6003b6f4d3
commit
07977ad94c
|
@ -41,6 +41,32 @@ concept HashCompatible = IsHashCompatible<Detail::Decay<T>, Detail::Decay<U>>;
|
|||
|
||||
// FIXME: remove once Clang formats these properly.
|
||||
// clang-format off
|
||||
|
||||
// Any indexable, sized, contiguous data structure.
|
||||
template<typename ArrayT, typename ContainedT, typename SizeT = size_t>
|
||||
concept ArrayLike = requires(ArrayT array, SizeT index)
|
||||
{
|
||||
{
|
||||
array[index]
|
||||
}
|
||||
-> SameAs<RemoveReference<ContainedT>&>;
|
||||
|
||||
{
|
||||
array.size()
|
||||
}
|
||||
-> SameAs<SizeT>;
|
||||
|
||||
{
|
||||
array.span()
|
||||
}
|
||||
-> SameAs<Span<RemoveReference<ContainedT>>>;
|
||||
|
||||
{
|
||||
array.data()
|
||||
}
|
||||
-> SameAs<RemoveReference<ContainedT>*>;
|
||||
};
|
||||
|
||||
template<typename Func, typename... Args>
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue