Skip to content

Instantly share code, notes, and snippets.

@danzimm
Created October 12, 2016 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danzimm/9e15c86487d7f217b85b759d4ce1b373 to your computer and use it in GitHub Desktop.
Save danzimm/9e15c86487d7f217b85b759d4ce1b373 to your computer and use it in GitHub Desktop.
std::hash extensions
template<typename T, typename U>
struct std::hash<std::pair<T, U>> {
std::size_t operator()(std::pair<T, U> const& value) const {
std::size_t thash = std::hash<T>{}(value.first);
std::size_t uhash = std::hash<U>{}(value.second);
// See boost::hash_combine for this
return uhash ^ ( thash << 1 );
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment