unordered_multiset::swap

交换两个容器的内容。

void swap(unordered_multiset& right);

参数

  • right
    交换的容器。

备注

成员函数将交换了 *this 和 right之间的控制序列。 unordered_multiset::get_allocator如果() == right.get_allocator(),在常数的时间执行,仅引发异常导致复制 Tr类型的对象存储字符,因此,它不在指定无效两个控制序列的元素的引用、指针或迭代器。 否则,它将执行大量的元素赋值,然后构造函数调用而与元素数目在两个控件的顺序。

示例

 

// std_tr1__unordered_set__unordered_multiset_swap.cpp 
// compile with: /EHsc 
#include <unordered_set> 
#include <iostream> 
 
typedef std::unordered_multiset<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>

命名空间: std

请参见

参考

<unordered_set>

unordered_multiset 类

swap 函数 (unordered_multiset)

其他资源

unordered_set 成员