最終更新日時:
が更新

履歴 編集

function
<hive>

std::hive::swap(C++26)

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

処理系

関連項目

名前 説明
swap 2つのhiveオブジェクトを入れ替える

参照