unordered_multimap::swap

更新 : 2007 年 11 月

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

void swap(unordered_multimap& right);

パラメータ

  • right
    交換先のコンテナ。

解説

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

使用例

 

// std_tr1__unordered_map__unordered_multimap_swap.cpp 
// compile with: /EHsc 
#include <unordered_map> 
#include <iostream> 
 
typedef std::tr1::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); 
    } 
 
 [c, 3] [b, 2] [a, 1]
 [f, 6] [e, 5] [d, 4]
 [c, 3] [b, 2] [a, 1]

必要条件

ヘッダー : <unordered_map>

名前空間 : std::tr1

参照

参照

<unordered_map>

unordered_multimap クラス

swap 関数 (unordered_multimap)