hash_map::swap
注意事項 |
---|
這個 API 已經過時。替代方案是 unordered_map 類別。 |
交換兩 hash_maps 的項目。
void swap(
hash_map& _Right
);
參數
- _Right
提供項目的引數 hash_map 將互換目標 hash_map。
備註
成員函式不無法在兩 hash_maps 的指定項目已交換參考、指標或 Iterator。
在 Visual C++ .NET 2003 中, <hash_map> 和 <hash_set> 標頭檔的成員不在 std 命名空間中,而是移至 stdext 命名空間。 如需詳細資訊,請參閱 stdext 命名空間。
範例
// hash_map_swap.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map <int, int> hm1, hm2, hm3;
hash_map <int, int>::iterator hm1_Iter;
typedef pair <int, int> Int_Pair;
hm1.insert ( Int_Pair ( 1, 10 ) );
hm1.insert ( Int_Pair ( 2, 20 ) );
hm1.insert ( Int_Pair ( 3, 30 ) );
hm2.insert ( Int_Pair ( 10, 100 ) );
hm2.insert ( Int_Pair ( 20, 200 ) );
hm3.insert ( Int_Pair ( 30, 300 ) );
cout << "The original hash_map hm1 is:";
for ( hm1_Iter = hm1.begin( ); hm1_Iter != hm1.end( ); hm1_Iter++ )
cout << " " << hm1_Iter -> second;
cout << "." << endl;
// This is the member function version of swap
// hm2 is said to be the argument hash_map;
// hm1 is said to be the target hash_map
hm1.swap( hm2 );
cout << "After swapping with hm2, hash_map hm1 is:";
for ( hm1_Iter = hm1.begin( ); hm1_Iter != hm1.end( ); hm1_Iter++ )
cout << " " << hm1_Iter -> second;
cout << "." << endl;
// This is the specialized template version of swap
swap( hm1, hm3 );
cout << "After swapping with hm3, hash_map hm1 is:";
for ( hm1_Iter = hm1.begin( ); hm1_Iter != hm1.end( ); hm1_Iter++ )
cout << " " << hm1_Iter -> second;
cout << "." << endl;
}
需求
標頭檔: <hash_map>
**命名空間:**stdext