mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
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
1 changed files with 17 additions and 0 deletions
|
@ -51,6 +51,21 @@ concept IteratorFunction = requires(Func func, Args... args)
|
||||||
}
|
}
|
||||||
-> SameAs<IterationDecision>;
|
-> 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
|
// clang-format on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +73,9 @@ using AK::Concepts::Arithmetic;
|
||||||
using AK::Concepts::Enum;
|
using AK::Concepts::Enum;
|
||||||
using AK::Concepts::FloatingPoint;
|
using AK::Concepts::FloatingPoint;
|
||||||
using AK::Concepts::Integral;
|
using AK::Concepts::Integral;
|
||||||
|
using AK::Concepts::IterableContainer;
|
||||||
using AK::Concepts::IteratorFunction;
|
using AK::Concepts::IteratorFunction;
|
||||||
|
using AK::Concepts::IteratorPairWith;
|
||||||
using AK::Concepts::Signed;
|
using AK::Concepts::Signed;
|
||||||
using AK::Concepts::Unsigned;
|
using AK::Concepts::Unsigned;
|
||||||
using AK::Concepts::VoidFunction;
|
using AK::Concepts::VoidFunction;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue