1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-04 02:41:19 +00:00

Support seed type different from std::size_t for hashCombine

This commit is contained in:
elsid 2021-11-13 16:14:50 +01:00
parent 4d09f791ab
commit 08a25c2b1f
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

View File

@ -1,15 +1,20 @@
#ifndef MISC_HASH_H
#define MISC_HASH_H
#include <cstddef>
#include <cstdint>
#include <functional>
namespace Misc
{
/// Implemented similar to the boost::hash_combine
template <class T>
inline void hashCombine(std::size_t& seed, const T& v)
template <class Seed, class T>
inline void hashCombine(Seed& seed, const T& v)
{
static_assert(sizeof(Seed) >= sizeof(std::size_t), "Resulting hash will be truncated");
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
seed ^= static_cast<Seed>(hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2));
}
}
#endif
#endif