From 08a25c2b1fc7c989077be6abea15ddcb678ac3b6 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 13 Nov 2021 16:14:50 +0100 Subject: [PATCH] Support seed type different from std::size_t for hashCombine --- components/misc/hash.hpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/components/misc/hash.hpp b/components/misc/hash.hpp index 30a9c41ee9..861df73772 100644 --- a/components/misc/hash.hpp +++ b/components/misc/hash.hpp @@ -1,15 +1,20 @@ #ifndef MISC_HASH_H #define MISC_HASH_H +#include +#include +#include + namespace Misc { /// Implemented similar to the boost::hash_combine - template - inline void hashCombine(std::size_t& seed, const T& v) + template + inline void hashCombine(Seed& seed, const T& v) { + static_assert(sizeof(Seed) >= sizeof(std::size_t), "Resulting hash will be truncated"); std::hash hasher; - seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2); + seed ^= static_cast(hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2)); } } -#endif \ No newline at end of file +#endif