mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +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
Notes:
sideshowbarker
2024-07-17 20:04:40 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/07977ad94cb Pull-request: https://github.com/SerenityOS/serenity/pull/12162 Reviewed-by: https://github.com/AtkinsSJ
1 changed files with 27 additions and 0 deletions
|
@ -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…
Add table
Reference in a new issue