Guest User

Untitled

a guest
Aug 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. Are there no specializations of std::hash for standard containers?
  2. std::unordered_set<std::array<int, 16> > test;
  3.  
  4. namespace std
  5. {
  6. template<typename T, size_t N>
  7. struct hash<array<T, N> >
  8. {
  9. typedef array<T, N> argument_type;
  10. typedef size_t result_type;
  11.  
  12. result_type operator()(const argument_type& a) const
  13. {
  14. hash<T> hasher;
  15. result_type h = 0;
  16. for (result_type i = 0; i < N; ++i)
  17. {
  18. h = h * 31 + hasher(a[i]);
  19. }
  20. return h;
  21. }
  22. };
  23. }
  24.  
  25. template <> struct hash<bool>;
  26. template <> struct hash<char>;
  27. template <> struct hash<signed char>;
  28. template <> struct hash<unsigned char>;
  29. template <> struct hash<char16_t>;
  30. template <> struct hash<char32_t>;
  31. template <> struct hash<wchar_t>;
  32. template <> struct hash<short>;
  33. template <> struct hash<unsigned short>;
  34. template <> struct hash<int>;
  35. template <> struct hash<unsigned int>;
  36. template <> struct hash<long>;
  37. template <> struct hash<long long>;
  38. template <> struct hash<unsigned long>;
  39. template <> struct hash<unsigned long long>;
  40. template <> struct hash<float>;
  41. template <> struct hash<double>;
  42. template <> struct hash<long double>;
  43. template<class T> struct hash<T*>;
Add Comment
Please, Sign In to add comment