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 와 교환합니다. 개별 요소에 대한 이동, 복사, 교환 연산을 호출하지 않습니다.
모든 반복자와 참조는 유효하게 유지됩니다.
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
알고리즘의 특수화
(함수 템플릿) |