다음을 통해 공유


multimap::swap

두 multimaps의 요소를 교환합니다.

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

매개 변수

  • _Right
    스왑 될 수 있는 요소를 제공 하는 multimap 또는 요소가 되는 multimap 갖는 교환 multimap _Left.

설명

멤버 함수가 없습니다 참조 나 포인터를 요소 요소는 교환 되는 두 multimaps에서 지정 하는 반복기를 무효화 합니다.

예제

// 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;
}
  
  
  

요구 사항

헤더: <map>

네임 스페이스: std

참고 항목

참조

multimap Class

표준 템플릿 라이브러리