unordered_map_swap
unordered_map_swap (std::unordered_map::swap — 내용 교환)
std::unordered_map 하나의 내용을 다른 객체 other와 맞바꾸는 멤버 함수예요.
출처: cppreference
본문
시그니처는 다음과 같아요.
void swap( unordered_map& other ) noexcept(/* see below */);
컨테이너의 내용을 other의 내용과 교환해요. 해시·동등 비교 함수 객체도 교환돼요. 모든 이터레이터와 참조는 유효하게 남아요(단 end() 값을 가리키던 이터레이터는 어떤 컨테이너를 가리킬지 지정되지 않아요).
매개변수
other: 내용을 교환할 컨테이너
복잡도
상수(constant)예요.
예제
#include <iostream>
#include <unordered_map>
int main()
{
std::unordered_map<int, char> a{{1, 'a'}};
std::unordered_map<int, char> b{{2, 'b'}};
a.swap(b);
std::cout << a.begin()->first << '\n'; // 2
}
함께 보기
std::swap(std::unordered_map):std::swap알고리즘을 특수화해요