AK: Add a concept for iterable containers
This concept describes a type with a begin()/end() pair that can function as an iterator, given the following criteria: - The return type of begin() is comparable with the return type of end(), and the comparison (with operator!=) yields a bool - The object returned from begin() can be pre-incremented - The iterator has an operator*() implementation
This commit is contained in:
parent
2891dca0cd
commit
f879e04133
Notes:
sideshowbarker
2024-07-18 08:32:05 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/f879e041339 Pull-request: https://github.com/SerenityOS/serenity/pull/8933
1 changed files with 17 additions and 0 deletions
|
@ -51,6 +51,21 @@ concept IteratorFunction = requires(Func func, Args... args)
|
|||
}
|
||||
-> SameAs<IterationDecision>;
|
||||
};
|
||||
|
||||
template<typename T, typename EndT>
|
||||
concept IteratorPairWith = requires(T it, EndT end)
|
||||
{
|
||||
*it;
|
||||
{ it != end } -> SameAs<bool>;
|
||||
++it;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
concept IterableContainer = requires
|
||||
{
|
||||
{ declval<T>().begin() } -> IteratorPairWith<decltype(declval<T>().end())>;
|
||||
};
|
||||
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
|
@ -58,7 +73,9 @@ using AK::Concepts::Arithmetic;
|
|||
using AK::Concepts::Enum;
|
||||
using AK::Concepts::FloatingPoint;
|
||||
using AK::Concepts::Integral;
|
||||
using AK::Concepts::IterableContainer;
|
||||
using AK::Concepts::IteratorFunction;
|
||||
using AK::Concepts::IteratorPairWith;
|
||||
using AK::Concepts::Signed;
|
||||
using AK::Concepts::Unsigned;
|
||||
using AK::Concepts::VoidFunction;
|
||||
|
|
Loading…
Add table
Reference in a new issue