multiset_swap

multiset_swap (std::multiset::swap — 내용 교환)

std::multiset 하나의 내용을 다른 객체 other와 맞바꾸는 멤버 함수예요.

출처: cppreference

본문

시그니처는 다음과 같아요.

void swap( multiset& other ) noexcept(/* see below */);   // (since C++17)

컨테이너의 내용을 other의 내용과 교환해요. 개별 원소에 대해 어떤 이동·복사·교환 연산도 호출하지 않아요. 모든 이터레이터와 참조는 유효하게 남아요. C++11까지는 비교 객체 comp도 교환돼요.

매개변수

  • other: 내용을 교환할 컨테이너

복잡도

상수(constant)예요.

예제

#include <iostream>
#include <set>
int main()
{
    std::multiset<int> a{1, 2};
    std::multiset<int> b{3, 4};
    a.swap(b);
    std::cout << *a.begin() << '\n';   // 3
}

함께 보기

  • std::swap(std::multiset): std::swap 알고리즘을 특수화해요

더 알아보기 (Learn more)

cppreference