unordered_multiset::swap

更新 : 2007 年 11 月

2 つのコンテナのコンテンツを交換します。

void swap(unordered_multiset& right);

パラメータ

  • right
    交換先のコンテナ。

解説

このメンバ関数は、*this と right の間で被制御シーケンスを交換します。unordered_multiset::get_allocator() == right.get_allocator() の場合は、処理が定数時間で実行されます。例外がスローされるのは、格納されている Tr 型の traits オブジェクトをコピーした場合のみで、2 つの被制御シーケンス内の要素を指定する反復子、参照、ポインタは一切無効化されません。それ以外の場合、2 つの被制御シーケンス内の要素数に比例した回数、要素の割り当てとコンストラクタ呼び出しが実行されます。

使用例

 

// std_tr1__unordered_set__unordered_multiset_swap.cpp 
// compile with: /EHsc 
#include <unordered_set> 
#include <iostream> 
 
typedef std::tr1::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); 
    } 
 
 [c] [b] [a]
 [f] [e] [d]
 [c] [b] [a]

必要条件

ヘッダー : <unordered_set>

名前空間 : std::tr1

参照

参照

<unordered_set>

unordered_multiset クラス

swap 関数 (unordered_multiset)