Bibliothèque C ++ Unordered_set - hash_function

La description

Il renvoie l'objet de fonction de hachage utilisé par le conteneur unordered_set.

Déclaration

Voici la déclaration pour std :: unordered_set :: hash_function.

C ++ 11

hasher hash_function() const;

Paramètres

aucun

Valeur de retour

Il renvoie la fonction de hachage.

Des exceptions

Une exception est levée si un objet de comparaison d'éléments lève une exception.

Veuillez noter que les arguments non valides provoquent un comportement indéfini.

Complexité temporelle

temps constant.

Exemple

L'exemple suivant montre l'utilisation de std :: unordered_set :: hash_function.

#include <iostream>
#include <string>
#include <unordered_set>

typedef std::unordered_set<std::string> stringset;

int main () {
   stringset myset;

   stringset::hasher fn = myset.hash_function();

   std::cout << "that contains: " << fn ("that") << std::endl;
   std::cout << "than contains: " << fn ("than") << std::endl;

   return 0;
}

Compilons et exécutons le programme ci-dessus, cela produira le résultat suivant -

that: 15843861542616104093
than: 18313131606624605886