std::hashstd::unique_ptr - cppreference.com (original) (raw)
| template< class T, class Deleter > struct hash<std::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.
When enabled, for a given std::unique_ptr<T, D> p, this specialization ensures thatstd::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.
[edit] Example
Possible output:
Foo(5) hash(up): acac20 hash(foo): acac20 *up==*foo: true Foo(5) hash(up): acac20 hash(other): acbc50 *up==*other: true ~Foo() ~Foo()
[edit] See also
| | hash function object (class template) [edit] | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |