flat_map::swap
flat_map::swap (내용 교환)
두 flat_map의 내용을 서로 바꾸는 멤버 함수예요. <flat_map> 헤더, C++23부터.
출처: cppreference
본문
swap()은 컨테이너의 내용을 other와 교환해요.
void swap( flat_map& other ) noexcept(/* see below */);
- 내부 키/값 벡터의 내용을 교환해요.
- 요소들의 개별 복사/이동을 호출하지 않고, 벡터 내부를 맞바꿔 비교적 저렴해요.
std::flat_map<int,int> a{{1,10}};
std::flat_map<int,int> b{{2,20},{3,30}};
a.swap(b);
// a == {{2,20},{3,30}}, b == {{1,10}}
자유 함수 std::swap(a, b)도 내부적으로 멤버 swap을 호출해요. flat_map의 내용을 바꿔치기할 때 쓰는 함수예요.