void swap(hive& x)
noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
allocator_traits<Allocator>::is_always_equal::value); // C++26
概要
他のhiveオブジェクトと内容を入れ替える。
効果
*thisの内容、capacity()、および要素ブロックの現在の容量制限(current-limits)をxのものと交換する。
戻り値
なし
計算量
定数時間
備考
この操作によって、要素へのポインタ・参照・イテレータが指す先の要素は変わらず、交換後もそれぞれの要素を指し続ける。ただしそれらが所属するコンテナは入れ替わる。
例
#include <hive>
#include <print>
int main()
{
std::hive<int> h1;
h1.insert(1);
h1.insert(2);
std::hive<int> h2;
h2.insert(3);
h1.swap(h2);
std::print("h1: ");
for (int x : h1) {
std::print("{} ", x);
}
std::println("");
std::print("h2: ");
for (int x : h2) {
std::print("{} ", x);
}
std::println("");
}
出力例
h1: 3
h2: 1 2
バージョン
言語
- C++26
処理系
- Clang: 22 ❌
- GCC: 16.1 ❌
- Visual C++: 2026 Update 2 ❌
関連項目
| 名前 | 説明 |
|---|---|
swap |
2つのhiveオブジェクトを入れ替える |
参照
- P0447R28 Introduction of
std::hiveto the standard library- C++26で
hiveが追加された
- C++26で