std::unordered_multiset<Key,Hash,KeyEqual,Allocator>:: swap
|
void
swap
(
unordered_multiset
&
other
)
;
|
(C++11以降)
(C++17まで) |
|
|
void
swap
(
unordered_multiset
&
other
)
noexcept
(
/* see below */
)
;
|
(C++17以降)
(constexpr C++26以降) |
|
コンテナの内容を other の内容と交換します。個々の要素に対するムーブ、コピー、swap操作は一切実行されません。
すべてのイテレータと参照は有効なまま維持されます。
end()
イテレータは無効化されます。
Hash
と
KeyEqual
は
Swappable
でなければならず、これらの型のオブジェクトは非メンバ
swap
に対する非修飾呼び出しを使用して交換されます。
もし
std::
allocator_traits
<
allocator_type
>
::
propagate_on_container_swap
::
value
が
true
の場合、アロケータは非メンバ
swap
に対する非修飾呼び出しを使用して交換されます。そうでない場合、それらは交換されず(かつ
get_allocator
(
)
!
=
other.
get_allocator
(
)
の場合、動作は未定義です)。
目次 |
パラメータ
| other | - | 内容を交換するコンテナ |
例外
|
|
(C++17まで) |
|
noexcept
指定:
noexcept
(
std::
allocator_traits
<
Allocator
>
::
is_always_equal
::
value
&&
std::
is_nothrow_swappable
<
Hash
>
::
value
|
(C++17以降) |
計算量
定数。
例
#include <iostream> #include <unordered_set> template<class Os, class Co> Os& operator<<(Os& os, const Co& co) { os << '{'; for (const auto& i : co) os << ' ' << i; return os << " } "; } int main() { std::unordered_multiset<int> a1{3, 1, 3, 2}, a2{5, 4, 5}; auto it1 = std::next(a1.begin()); auto it2 = std::next(a2.begin()); const int& ref1 = *(a1.begin()); const int& ref2 = *(a2.begin()); std::cout << a1 << a2 << *it1 << ' ' << *it2 << ' ' << ref1 << ' ' << ref2 << '\n'; a1.swap(a2); std::cout << a1 << a2 << *it1 << ' ' << *it2 << ' ' << ref1 << ' ' << ref2 << '\n'; // スワップ前に一方のコンテナ内の要素を参照するすべてのイテレータは、 // スワップ後にも他方のコンテナ内の同じ要素を参照することに注意。 // 参照についても同様である。 }
出力例:
{ 2 3 3 1 } { 4 5 5 } 3 5 2 4
{ 4 5 5 } { 2 3 3 1 } 3 5 2 4
関連項目
|
std::swap
アルゴリズムを特殊化する
(関数テンプレート) |