std::hash

From Cppreference

Jump to: navigation, search
Defined in header <functional>

template< class Key >
struct hash;
(C++11 feature)

The hash template defines a hash function object such that if two objects K and M of the same type Key compare equal, then std::hash(K)==std::hash(M), although the reverse is not necessarily true.

The unordered associative containers std::unordered_set, std::unordered_multiset, std::unordered_map, std::unordered_multimap use specializations of the template std::hash as the default hash function.

Contents

[edit] Member types

argument_type Key
result_type std::size_t

[edit] Member functions

(constructor)
constructs a hash function object
(public member function)
operator()
calculate the hash of the argument
(public member function)

[edit] Standard specializations for basic types

Defined in header <functional>

template<> struct hash<bool>;

template<> struct hash<char>;
template<> struct hash<signed char>;
template<> struct hash<unsigned char>;
template<> struct hash<char16_t>;
template<> struct hash<char32_t>;
template<> struct hash<wchar_t>;
template<> struct hash<short>;
template<> struct hash<unsigned short>;
template<> struct hash<int>;
template<> struct hash<unsigned int>;
template<> struct hash<long>;
template<> struct hash<long long>;
template<> struct hash<unsigned long>;
template<> struct hash<unsigned long long>;
template<> struct hash<float>;
template<> struct hash<double>;
template<> struct hash<long double>;

template< class T > struct hash<T*>;

[edit] Standard specializations for library types

std::hash<std::string>
std::hash<std::u16string>
std::hash<std::u32string>
std::hash<std::wstring>
(C++11)
(C++11)
(C++11)
(C++11)
hash support for strings
(class template specialization)
std::hash<std::error_code> (C++11)
hash support for std::error_code
(class template specialization)
std::hash<std::bitset> (C++11)
hash support for std::bitset
(class template specialization)
std::hash<std::unique_ptr> (C++11)
hash support for std::unique_ptr
(class template specialization)
std::hash<std::shared_ptr> (C++11)
hash support for std::shared_ptr
(class template specialization)
std::hash<std::type_index> (C++11)
hash support for std::type_index
(class template specialization)
std::hash<std::vector<bool>> (C++11)
hash support for std::vector<bool>
(class template specialization)
std::hash<std::thread::id> (C++11)
hash support for std::thread::id
(class template specialization)