std::hash
Aus cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody> template<class T, class Deleter> struct hash<unique_ptr<T, Deleter>>; |
(seit C++11) | |
Die Vorlage Spezialisierung std::hash für
std::unique_ptr<T, Deleter> ermöglicht es Benutzern, Hashes von Objekten des Typs std::unique_ptr<T, Deleter> zu erhalten .Original:
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 text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Für eine gegebene
std::unique_ptr<T, Deleter> p sorgt diese Spezialisierung dass std::hash<std::unique_ptr<T, Deleter>>()(p) == std::hash<T*>()(p.get()) .Original:
For a given
std::unique_ptr<T, Deleter> p, this specialization ensures that std::hash<std::unique_ptr<T, Deleter>>()(p) == std::hash<T*>()(p.get()).The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Beispiel
#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...
Siehe auch
(C++11) |
Funktionsobjekt zur Erzeugung von Hashwerten (Klassen-Template) |