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

La description

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

Déclaration

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

C ++ 11

allocator_type get_allocator() const noexcept;

Paramètres

Aucun

Valeur de retour

Renvoie un allocateur associé à forward_list.

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

#include <iostream>
#include <forward_list>

using namespace std;

int main(void) {

   forward_list<int> fl = {1, 2, 3, 4, 5};
   int *p = NULL;

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

   for (int i = 0; i < 5; ++i)
      p[i] = i + 1;

   cout << "List contains following elements" << endl;

   for (int i = 0; i < 5; ++i)
      cout << p[i] << endl;

   return 0;
}

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

List contains following elements
1
2
3
4
5