Created
February 24, 2016 19:41
-
-
Save gyakoo/1f77661d670876e6d0c1 to your computer and use it in GitHub Desktop.
Variadic template function to make a hash using std::hash and combining them
This file contains 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
// recursive variadic template hash | |
// base case | |
template<typename T> | |
std::size_t makeHash(const T& v) | |
{ | |
return std::hash<T>()(v); | |
} | |
// recursive variadic template hash | |
template<typename T, typename... Args> | |
std::size_t makeHash(T first, Args ... args) | |
{ | |
//auto n = sizeof...(Args); | |
std::size_t h = std::hash<T>()(first) ^ (makeHash(args...) << 1); | |
return h; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very useful resource, thank you!