set::swap
Exchanges the elements of two sets.
void swap(
set<Key, Traits, Allocator>& _Right
);
매개 변수
- _Right
The argument set providing the elements to be swapped with the target set.
설명
The member function invalidates no references, pointers, or iterators that designate elements in the two sets whose elements are being exchanged.
예제
// 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;
}
요구 사항
헤더: <설정>
네임스페이스: std