다음을 통해 공유


set::swap

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

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

매개 변수

  • _Right
    대상 집합으로 교체 하는 요소를 제공 하는 인수를 설정 합니다.

설명

없는 참조 나 포인터 요소를 교환 하는 두 집합의 요소를 지정 하는 반복기 멤버 함수를 무효화 합니다.

예제

// set_swap.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   set <int>::iterator s1_Iter;

   s1.insert( 10 );
   s1.insert( 20 );
   s1.insert( 30 );
   s2.insert( 100 );
   s2.insert( 200 );
   s3.insert( 300 );

   cout << "The original set s1 is:";
   for ( s1_Iter = s1.begin( ); s1_Iter != s1.end( ); s1_Iter++ )
      cout << " " << *s1_Iter;
   cout   << "." << endl;

   // This is the member function version of swap
   s1.swap( s2 );

   cout << "After swapping with s2, list s1 is:";
   for ( s1_Iter = s1.begin( ); s1_Iter != s1.end( ); s1_Iter++ )
      cout << " " << *s1_Iter;
   cout  << "." << endl;

   // This is the specialized template version of swap
   swap( s1, s3 );

   cout << "After swapping with s3, list s1 is:";
   for ( s1_Iter = s1.begin( ); s1_Iter != s1.end( ); s1_Iter++ )
      cout << " " << *s1_Iter;
   cout   << "." << endl;
}
  
  
  

요구 사항

헤더: <set>

네임 스페이스: std

참고 항목

참조

set Class

set::swap, set::begin, 및 set::end

표준 템플릿 라이브러리