std::hash<std::unique_ptr> (3) - Linux Manuals
std::hash<std::unique_ptr>: std::hash<std::unique_ptr>
Command to display std::hash<std::unique_ptr>
manual in Linux: $ man 3 std::hash<std::unique_ptr>
NAME
std::hash<std::unique_ptr> - std::hash<std::unique_ptr>
Synopsis
template<class T, class Deleter> struct hash<unique_ptr<T, Deleter>>; (since C++11)
The template specialization of std::hash for std::unique_ptr<T, Deleter> allows users to obtain hashes of objects of type std::unique_ptr<T, Deleter>.
The specialization std::hash<std::unique_ptr<T,D>> is enabled (see std::hash) if std::hash<typename std::unique_ptr<T,D>::pointer> is enabled, and is disabled otherwise. (since C++17)
When enabled,
(since C++17) for a given std::unique_ptr<T, D> p, this specialization ensures that std::hash<std::unique_ptr<T, D>>()(p) == std::hash<typename std::unique_ptr<T, D>::pointer>()(p.get()).
The member functions of this specialization are not guaranteed to be noexcept because the pointer may be a fancy pointer and its hash might throw.
Example
// Run this code
#include <iostream>
#include <memory>
#include <functional>
struct Foo {
Foo() { std::cout << "Foo...\n"; }
~Foo() { std::cout << "~Foo...\n\n"; }
};
int main()
{
Foo* foo = new Foo();
std::unique_ptr<Foo> up(foo);
std::cout << "hash(up): " << std::hash<std::unique_ptr<Foo>>()(up) << '\n';
std::cout << "hash(foo): " << std::hash<Foo*>()(foo) << '\n';
}
Output:
Foo...
hash(up): 3686401041
hash(foo): 3686401041
~Foo...
See also
hash hash function object
(class template)
(C++11)
Pages related to std::hash<std::unique_ptr>
- std::hash<std::error_code> (3) - std::hash<std::error_code>
- std::hash<std::error_condition> (3) - std::hash<std::error_condition>
- std::hash<std::experimental::optional> (3) - std::hash<std::experimental::optional>
- std::hash<std::optional> (3) - std::hash<std::optional>
- std::hash<std::thread::id> (3) - std::hash<std::thread::id>
- std::hash<std::type_index> (3) - std::hash<std::type_index>
- std::hash<std::variant> (3) - std::hash<std::variant>
- std::hash(std::bitset) (3) - std::hash(std::bitset)
- std::hash(std::experimental::observer_ptr) (3) - std::hash(std::experimental::observer_ptr)
- std::hash(std::experimental::propagate_const) (3) - std::hash(std::experimental::propagate_const)
- std::hash(std::experimental::shared_ptr) (3) - std::hash(std::experimental::shared_ptr)
- std::hash(std::experimental::string_view,std::experimental::wstring_view, (3) - std::hash(std::experimental::string_view,std::experimental::wstring_view,
- std::hash(std::experimental::string_view,std::experimental::wstring_view,std::experimental::u16string_view,std::experimental::u32string_view) (3) - std::hash(std::experimental::string_view,std::experimental::wstring_view,std::experimental::u16string_view,std::experimental::u32string_view)