From eb832213a06eab8216cae6043c38af84294b35a1 Mon Sep 17 00:00:00 2001 From: Fabian Posch Date: Tue, 9 Jan 2024 14:38:32 -0500 Subject: [PATCH] make uuid_t hashable --- include/db_lib/db_types.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/db_lib/db_types.hpp b/include/db_lib/db_types.hpp index bf1b4db..93a9692 100644 --- a/include/db_lib/db_types.hpp +++ b/include/db_lib/db_types.hpp @@ -117,6 +117,17 @@ struct is_map_key_type_same_as_enum { }; +// hash operator to be able use uuid_t as a hashmap key +template<> +struct std::hash { + std::size_t operator()(const db::uuid_t& k) const { + using std::size_t; + using std::hash; + + return hash()(hash()(k.uuid_upper) ^ hash()(k.uuid_lower)); + } +}; + /** * @brief Generate type conversion for enum class macros in the libpqxx library