util/IntrusiveHashSet: add concept checks

This commit is contained in:
Max Kellermann 2024-09-02 18:59:45 +02:00 committed by Max Kellermann
parent a3a07280e8
commit 523519182a
1 changed files with 16 additions and 1 deletions

View File

@ -11,6 +11,21 @@
#include <concepts> // for std::regular_invocable #include <concepts> // for std::regular_invocable
#include <numeric> // for std::accumulate() #include <numeric> // for std::accumulate()
template<typename Operators, typename Item>
concept IntrusiveHashSetOperatorsConcept = requires(const Operators &ops,
const Item &c, const Item &c2)
{
{ ops.get_key(c) } noexcept;
/* note: no "noexcept" here because std::hash is not
noexcept */
{ ops.hash(ops.get_key(c)) } -> std::same_as<std::size_t>;
/* note: no "noexcept" here because std::equal_to is not
noexcept */
{ ops.equal(ops.get_key(c), ops.get_key(c2)) } -> std::same_as<bool>;
};
struct IntrusiveHashSetOptions { struct IntrusiveHashSetOptions {
bool constant_time_size = false; bool constant_time_size = false;
@ -123,7 +138,7 @@ struct IntrusiveHashSetOperators {
* `equal` * `equal`
*/ */
template<typename T, std::size_t table_size, template<typename T, std::size_t table_size,
typename Operators, IntrusiveHashSetOperatorsConcept<T> Operators,
typename HookTraits=IntrusiveHashSetBaseHookTraits<T>, typename HookTraits=IntrusiveHashSetBaseHookTraits<T>,
IntrusiveHashSetOptions options=IntrusiveHashSetOptions{}> IntrusiveHashSetOptions options=IntrusiveHashSetOptions{}>
class IntrusiveHashSet { class IntrusiveHashSet {