Bibliothèque de cartes C ++ - fonction get_allocator ()

La description

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

Déclaration

Voici la déclaration de la fonction std :: multimap :: get_allocator () sous forme d'en-tête std :: map.

C ++ 98

allocator_type get_allocator() const;

C ++ 11

allocator_type get_allocator() const noexcept;

Paramètres

Aucun

Valeur de retour

Renvoie un allocateur associé à multimap.

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 :: multimap :: get_allocator ().

#include <iostream>
#include <map>

using namespace std;

int main(void) {
   multimap<char, int> m;
   pair<const char, int> *p;

   p = m.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