hash_set::swap (STL/CLR)
交換兩個容器的內容。
void swap(hash_set<Key>% right);
參數
- right
要交換內容的容器。
備註
成員函式交換在 this 和 right的控制順序。 它在常數時間執行,而且不會擲回例外狀況。 您將它當做一個快速的方法交換兩個容器的內容。
範例
// cliext_hash_set_swap.cpp
// compile with: /clr
#include <cliext/hash_set>
typedef cliext::hash_set<wchar_t> Myhash_set;
int main()
{
Myhash_set c1;
c1.insert(L'a');
c1.insert(L'b');
c1.insert(L'c');
// display initial contents " a b c"
for each (wchar_t elem in c1)
System::Console::Write(" {0}", elem);
System::Console::WriteLine();
// construct another container with repetition of values
Myhash_set c2;
c2.insert(L'd');
c2.insert(L'e');
c2.insert(L'f');
for each (wchar_t elem in c2)
System::Console::Write(" {0}", elem);
System::Console::WriteLine();
// swap and redisplay
c1.swap(c2);
for each (wchar_t elem in c1)
System::Console::Write(" {0}", elem);
System::Console::WriteLine();
for each (wchar_t elem in c2)
System::Console::Write(" {0}", elem);
System::Console::WriteLine();
return (0);
}
需求
標頭: <cliext/hash_set>
命名空間: cliext