diff --git a/Util/StdHashExtensions.h b/Util/StdHashExtensions.h index 29663f1d3..d2f2fc4fe 100644 --- a/Util/StdHashExtensions.h +++ b/Util/StdHashExtensions.h @@ -32,13 +32,41 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +// this is largely inspired by boost's hash combine +template +inline void hash_combine(std::size_t &seed, const T& val) +{ + seed ^= std::hash()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2); +} + +template +inline void hash_val(std::size_t &seed, const T& val) +{ + hash_combine(seed, val); +} + +template +inline void hash_val(std::size_t &seed, const T& val, const Types& ... args) +{ + hash_combine(seed, val); + hash_val(seed, args ...); +} + +template +inline std::size_t hash_val( const Types&... args) +{ + std::size_t seed = 0; + hash_val(seed, args...); + return seed; +} + namespace std { template <> struct hash> { size_t operator()(const std::pair &pair) const { - return std::hash()(pair.first) ^ std::hash()(pair.second); + return hash_val(pair.first, pair.second); } }; }