From 838c4b9a45a50f252c7b20d14570b0b7463709ab Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Wed, 8 Jan 2025 23:40:52 +0100 Subject: Finish work on hashing probably --- asl/box.hpp | 8 +++ asl/buffer.hpp | 2 + asl/hash.hpp | 6 ++ asl/meta.hpp | 2 +- asl/option.hpp | 16 ++++++ asl/span.hpp | 6 -- asl/status.hpp | 13 ++++- asl/status_or.hpp | 15 ++++- asl/tests/hash_tests.cpp | 124 +++++++++++++++++++++++++++++++++++++++++- asl/tests/status_or_tests.cpp | 4 -- asl/tests/status_tests.cpp | 7 --- 11 files changed, 176 insertions(+), 27 deletions(-) (limited to 'asl') diff --git a/asl/box.hpp b/asl/box.hpp index d018c03..340a37c 100644 --- a/asl/box.hpp +++ b/asl/box.hpp @@ -5,6 +5,7 @@ #include "asl/annotations.hpp" #include "asl/memory.hpp" #include "asl/utility.hpp" +#include "asl/hash.hpp" namespace asl { @@ -82,6 +83,13 @@ public: { return m_ptr == nullptr; } + + template + requires hashable + friend H AslHashValue(H h, const box& b) + { + return H::combine(ASL_MOVE(h), *b); + } }; template diff --git a/asl/buffer.hpp b/asl/buffer.hpp index 7d33c73..93f811b 100644 --- a/asl/buffer.hpp +++ b/asl/buffer.hpp @@ -6,6 +6,7 @@ #include "asl/memory.hpp" #include "asl/assert.hpp" #include "asl/span.hpp" +#include "asl/hash.hpp" namespace asl { @@ -391,6 +392,7 @@ public: } template + requires hashable friend H AslHashValue(H h, const buffer& b) { return H::combine_contiguous(ASL_MOVE(h), b.as_span()); diff --git a/asl/hash.hpp b/asl/hash.hpp index 5f81e92..d3a12bd 100644 --- a/asl/hash.hpp +++ b/asl/hash.hpp @@ -120,6 +120,12 @@ constexpr H AslHashValue(H h, bool value) template constexpr void AslHashValue(H h, T*); // Don't hash pointers +template +constexpr H AslHashValue(H h, const span& s) +{ + return H::combine_contiguous(ASL_MOVE(h), span{s.data(), s.size()}); +} + template constexpr uint64_t hash_value(const T& value) { diff --git a/asl/meta.hpp b/asl/meta.hpp index 8940ec6..e77f4a7 100644 --- a/asl/meta.hpp +++ b/asl/meta.hpp @@ -197,7 +197,7 @@ template struct is_uniquely_represented : true_type {}; template<> struct is_uniquely_represented : true_type {}; template<> struct is_uniquely_represented : true_type {}; -template concept uniquely_represented = is_uniquely_represented::value; +template concept uniquely_represented = is_uniquely_represented>::value; template concept equality_comparable_with = requires (const un_cvref_t& a, const un_cvref_t& b) diff --git a/asl/option.hpp b/asl/option.hpp index eb6a91c..f7a3eab 100644 --- a/asl/option.hpp +++ b/asl/option.hpp @@ -5,6 +5,7 @@ #include "asl/maybe_uninit.hpp" #include "asl/functional.hpp" #include "asl/annotations.hpp" +#include "asl/hash.hpp" namespace asl { @@ -485,8 +486,23 @@ public: { return has_value() ? ASL_MOVE(*this) : invoke(ASL_FWD(f)); } + + template + requires (!uniquely_represented