map_swap
map_swap (std::map::swap — 내용 교환)
std::map 하나의 내용을 다른 객체 other와 맞바꾸는 멤버 함수예요.
출처: cppreference
본문
시그니처는 다음과 같아요.
void swap( map& other ) noexcept(/* see below */); // (since C++17)
컨테이너의 내용을 other의 내용과 교환해요. 개별 원소에 대해 어떤 이동·복사·교환 연산도 호출하지 않아요. 모든 이터레이터와 참조는 유효하게 남아요. C++11까지는 비교 객체 comp도 교환돼요.
매개변수
other: 내용을 교환할 컨테이너
복잡도
상수(constant)예요.
예제
#include <iostream>
#include <map>
int main()
{
std::map<int, char> a{{1, 'a'}};
std::map<int, char> b{{2, 'b'}};
a.swap(b);
std::cout << a.begin()->first << '\n'; // 2
}
함께 보기
std::swap(std::map):std::swap알고리즘을 특수화해요