unordered_set::swap

交換兩個容器的內容。

void swap(unordered_set& right);

參數

  • right
    要交換的容器。

備註

成員函式交換受控制的序列之間*this和right。如果unordered_set::get_allocator() == right.get_allocator(),它會固定的時間,就會擲回例外狀況只產生的複製預存的特性的物件型別Tr,而這會導致沒有參考、 指標或 iterator,以指定兩個的受控制序列中的項目。否則,它會在兩個的受控制序列中執行了數個項目工作分派和建構函式呼叫的項目數目成正比。

範例

 

// std_tr1__unordered_set__unordered_set_swap.cpp 
// compile with: /EHsc 
#include <unordered_set> 
#include <iostream> 
 
typedef std::unordered_set<char> Myset; 
int main() 
    { 
    Myset c1; 
 
    c1.insert('a'); 
    c1.insert('b'); 
    c1.insert('c'); 
 
// display contents " [c] [b] [a]" 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
    Myset c2; 
 
    c2.insert('d'); 
    c2.insert('e'); 
    c2.insert('f'); 
 
    c1.swap(c2); 
 
// display contents " [f] [e] [d]" 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
    swap(c1, c2); 
 
// display contents " [c] [b] [a]" 
    for (Myset::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << *it << "]"; 
    std::cout << std::endl; 
 
    return (0); 
    } 
 
  

需求

標頭: <unordered_set>

Namespace: 標準

請參閱

參考

<unordered_set>

unordered_set Class

swap Function (unordered_set)

其他資源

<unordered_set> 成員