Last active
August 29, 2015 14:12
-
-
Save catchouli/a33ea252294b5b3be1ce to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <functional> | |
/** Combine hash in seed with hash of t1 */ | |
template <typename T1> | |
void hash_combine(size_t& seed, const T1& t1) | |
{ | |
// Combine hashes | |
seed ^= std::hash<T1>()(t1) + 0x9e3779b9 + (seed << 6) + (seed >> 2); | |
} | |
/** Combine hash in seed with hashes in t1, t2, args... */ | |
template <typename T1, typename T2, typename... Ts> | |
void hash_combine(size_t& seed, const T1& t1, const T2& t2, const Ts&... args) | |
{ | |
// Process t1 and then the rest of the argument pack | |
hash_combine(seed, t1); | |
hash_combine(seed, t2, args...); | |
} | |
/** Calculate a combined hash from args */ | |
template <typename... Args> | |
size_t& combined_hash(const Args&... args) | |
{ | |
size_t hash = 0; | |
hash_combine(hash, args...); | |
return hash; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment