Bibliothèque C ++ Unordered_multimap - fonction swap ()

La description

La fonction C ++ std::unordered_multimap::swap() échange le contenu du premier unordered_multimap avec un autre.

Déclaration

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

C ++ 11

void swap(unordered_multimap& umm);

Paramètres

umm - Un autre objet unordered_multimap.

Valeur de retour

Aucun

Complexité temporelle

Constante ie O (1)

Exemple

L'exemple suivant montre l'utilisation de la fonction std :: unordered_multimap :: swap ().

#include <iostream>
#include <unordered_map>

using namespace std;

int main(void) {
   unordered_multimap<char, int> umm1 = { 
            {'a', 1},
            {'b', 2},
            {'c', 3},
            {'d', 4},
            {'e', 5},
            };

   unordered_multimap<char, int> umm2;

   umm1.swap(umm2);

   cout << "Unordered multimap contains following elements" << endl;

   for (auto it = umm2.begin(); it != umm2.end(); ++it)
      cout << it->first << " = " << it->second << endl;

   return 0;
}

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

Unordered multimap contains following elements
e = 5
a = 1
b = 2
c = 3
d = 4