Skip to content

Instantly share code, notes, and snippets.

@gyakoo
Created February 24, 2016 19:41
Show Gist options
  • Save gyakoo/1f77661d670876e6d0c1 to your computer and use it in GitHub Desktop.
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
// 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;
}
@emctague
Copy link

Very useful resource, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment