unordered_multimap::swap

交換兩個容器的內容。

void swap(unordered_multimap& right);

參數

  • right
    要交換的容器。

備註

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

範例

 

// std_tr1__unordered_map__unordered_multimap_swap.cpp 
// compile with: /EHsc 
#include <unordered_map> 
#include <iostream> 
 
typedef std::unordered_multimap<char, int> Mymap; 
int main() 
    { 
    Mymap c1; 
 
    c1.insert(Mymap::value_type('a', 1)); 
    c1.insert(Mymap::value_type('b', 2)); 
    c1.insert(Mymap::value_type('c', 3)); 
 
// display contents " [c 3] [b 2] [a 1]" 
    for (Mymap::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << it->first << ", " << it->second << "]"; 
    std::cout << std::endl; 
 
    Mymap c2; 
 
    c2.insert(Mymap::value_type('d', 4)); 
    c2.insert(Mymap::value_type('e', 5)); 
    c2.insert(Mymap::value_type('f', 6)); 
 
    c1.swap(c2); 
 
// display contents " [f 6] [e 5] [d 4]" 
    for (Mymap::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << it->first << ", " << it->second << "]"; 
    std::cout << std::endl; 
 
    swap(c1, c2); 
 
// display contents " [c 3] [b 2] [a 1]" 
    for (Mymap::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " [" << it->first << ", " << it->second << "]"; 
    std::cout << std::endl; 
 
    return (0); 
    } 
 
  

需求

標頭: <unordered_map>

Namespace: 標準

請參閱

參考

<unordered_map>

unordered_multimap Class

swap Function (unordered_multimap)

其他資源

<unordered_map> 成員