Namespaces
Variants

std::swap(std::hive)

cppreference.net에서

 
 
 
 
헤더에 정의됨 <hive>
void swap( std::hive& lhs, std::hive& rhs ) noexcept(/* see below */);
(since C++26)

특수화합니다 std::swap 알고리즘을 std::hive. 의 내용을 교환합니다. lhs와 rhs. 호출합니다. lhs.swap(rhs).\n

매개변수

lhs, rhs\n -\n 내용을 교환할 컨테이너\n

복잡도

상수.\n

예외

noexcept 명세:\n  
noexcept(noexcept(lhs.swap(rhs)))

예제

#include <algorithm>
#include <iostream>
#include <hive>

int main()
{
    std::hive<int> alice{1, 2, 3};
    std::hive<int> bob{7, 8, 9, 10};

    auto print = [](const int& n) { std::cout << ' ' << n; };

    // Print state before swap
    std::cout << "Alice:";
    std::for_each(alice.begin(), alice.end(), print);
    std::cout << "\nBobby:";
    std::for_each(bob.begin(), bob.end(), print);
    std::cout << '\n';

    std::cout << "-- SWAP\n";
    std::swap(alice, bob);

    // Print state after swap
    std::cout << "Alice:";
    std::for_each(alice.begin(), alice.end(), print);
    std::cout << "\nBobby:";
    std::for_each(bob.begin(), bob.end(), print);
    std::cout << '\n';
}

출력:\n

Alice: 1 2 3
Bobby: 7 8 9 10
-- SWAP
Alice: 7 8 9 10
Bobby: 1 2 3

참조

내용을 교환합니다
(공개 멤버 함수)