std::swap(std::hive)
Определён в заголовке <hive> | ||
|---|---|---|
void swap( std::hive& lhs, std::hive& rhs ) noexcept(/* see below */); | (начиная с C++26) |
Специализирует алгоритм std::swap для std::hive. Меняет местами содержимое lhs и rhs. Вызывает lhs.swap(rhs).
Параметры
| lhs, rhs | - | контейнеры, содержимое которых нужно поменять местами |
Сложность
Константная.
Исключения
noexcept спецификация: 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';
}
Вывод:
Alice: 1 2 3 Bobby: 7 8 9 10 -- SWAP Alice: 7 8 9 10 Bobby: 1 2 3
См. также
| меняет содержимое местами (открытая функция-член) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/container/hive/swap2