Udostępnij za pośrednictwem


multimap::swap

Wymiany elementów dwóch multimaps.

void swap(
   multimap<Key, Type, Traits, Allocator>& _Right
);

Parametry

  • _Right
    Mapa wielokrotnego dopasowania, zapewniając zamianę elementów lub Mapa wielokrotnego dopasowania, której elementy są wymieniane z tymi Mapa wielokrotnego dopasowania _Left.

Uwagi

Funkcja Członkowskie unieważnia nie odwołań, wskaźniki lub Iteratory, które wyznacza elementy w dwóch multimaps, której elementy są wymianie.

Przykład

// multimap_swap.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main( )
{
   using namespace std;
   multimap <int, int> m1, m2, m3;
   multimap <int, int>::iterator m1_Iter;
   typedef pair <int, int> Int_Pair;

   m1.insert ( Int_Pair ( 1, 10 ) );
   m1.insert ( Int_Pair ( 2, 20 ) );
   m1.insert ( Int_Pair ( 3, 30 ) );
   m2.insert ( Int_Pair ( 10, 100 ) );
   m2.insert ( Int_Pair ( 20, 200 ) );
   m3.insert ( Int_Pair ( 30, 300 ) );

   cout << "The original multimap m1 is:";
   for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
      cout << " " << m1_Iter -> second;
   cout   << "." << endl;

   // This is the member function version of swap
   m1.swap( m2 );

   cout << "After swapping with m2, multimap m1 is:";
   for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
      cout << " " << m1_Iter -> second;
   cout  << "." << endl;

   // This is the specialized template version of swap
   swap( m1, m3 );

   cout << "After swapping with m3, multimap m1 is:";
   for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
      cout << " " << m1_Iter -> second;
   cout   << "." << endl;
}
  
  
  

Wymagania

Nagłówek: <map>

Obszar nazw: std

Zobacz też

Informacje

multimap Class

Standardowa biblioteka szablonu