multiset::swap
交換兩個多重集 (Multiset) 的項目。
void swap(
multiset<Key, Compare, Allocator>& _Right
);
參數
- _Right
提供項目的引數多重集都會交換與目標多重集。
備註
成員函式不失效。兩個多重集 (Multiset) 的指定項目已交換參考、指標或 Iterator。
範例
// multiset_swap.cpp
// compile with: /EHsc
#include <set>
#include <iostream>
int main( )
{
using namespace std;
multiset <int> ms1, ms2, ms3;
multiset <int>::iterator ms1_Iter;
ms1.insert( 10 );
ms1.insert( 20 );
ms1.insert( 30 );
ms2.insert( 100 );
ms2.insert( 200 );
ms3.insert( 300 );
cout << "The original multiset ms1 is:";
for ( ms1_Iter = ms1.begin( ); ms1_Iter != ms1.end( ); ms1_Iter++ )
cout << " " << *ms1_Iter;
cout << "." << endl;
// This is the member function version of swap
ms1.swap( ms2 );
cout << "After swapping with ms2, list ms1 is:";
for ( ms1_Iter = ms1.begin( ); ms1_Iter != ms1.end( ); ms1_Iter++ )
cout << " " << *ms1_Iter;
cout << "." << endl;
// This is the specialized template version of swap
swap( ms1, ms3 );
cout << "After swapping with ms3, list ms1 is:";
for ( ms1_Iter = ms1.begin( ); ms1_Iter != ms1.end( ); ms1_Iter++ )
cout << " " << *ms1_Iter;
cout << "." << endl;
}
需求
標題: <set>
命名空間: std