Bibliothèque C ++ Unordered_map - fonction get_allocator ()

La description

La fonction C ++ std::unordered_map::get_allocator() renvoie un allocateur associé à unordered_map.

Déclaration

Voici la déclaration de la fonction std :: unordered_map :: get_allocator () de l'en-tête std :: unordered_map.

C ++ 11

allocator_type get_allocator() const noexcept;

Paramètres

Aucun

Valeur de retour

Renvoie un allocateur associé à unordered_map.

Des exceptions

Cette fonction membre ne lève jamais d'exception.

Complexité temporelle

Constante ie O (1)

Exemple

L'exemple suivant montre l'utilisation de la fonction std :: unordered_map :: get_allocator ().

#include <iostream>
#include <unordered_map>

using namespace std;

int main(void) {
   unordered_map<char, int> um;
   pair<const char, int> *p;

   p = um.get_allocator().allocate(5);

   cout << "Allocated size = " <<  sizeof(*p) * 5 << endl;

   return 0;
}

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

Allocated size = 40