最終更新日時:
が更新

履歴 編集

function
<hive>

std::hive::operator=(C++26)

hive& operator=(const hive& x); // (1) C++26

hive& operator=(hive&& x)
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
           allocator_traits<Allocator>::is_always_equal::value); // (2) C++26

hive& operator=(initializer_list<T> il); // (3) C++26

概要

  • (1) : コピー代入。
  • (2) : ムーブ代入。
  • (3) : 初期化子リストを代入。

事前条件

  • (1) : 型Thiveに対してCopyInsertableかつCopyAssignableであること。
  • (2) : allocator_traits<Allocator>::propagate_on_container_move_assignment::value || allocator_traits<Allocator>::is_always_equal::valuefalseである場合、型Thiveに対してMoveInsertableかつMoveAssignableであること。

効果

  • (1) : *thisの全ての要素は、コピー代入されるか破棄される。xの全ての要素は、相対順序を保ったまま*thisにコピーされる。
  • (2) : *thisの全ての要素は、ムーブ代入されるか破棄される。
    • allocator_traits<Allocator>::propagate_on_container_move_assignment::value || get_allocator() == x.get_allocator()trueの場合、xの各要素ブロックを*thisへ移動する。xの要素を指すポインタ・参照は、*thisのメンバとなった同じ要素を指し続ける。xの要素を指すイテレータは、それらの要素を指し続けるが、*thisのイテレータとして振る舞う。
    • 上記がfalseの場合、xの各要素を*thisへ移動する。xの要素を指す参照・ポインタ・イテレータ、およびxの終端イテレータは無効になる。
  • (3) : ilの全ての要素を*thisにコピー代入する。

事後条件

  • (2) : x.empty() == trueとなる。*thisの要素の相対順序は、呼び出し前のxの要素の相対順序と同じである。

戻り値

*this

計算量

  • (1) : size() + x.size()に対して線形時間
  • (2) : size()に対して線形時間。さらにallocator_traits<Allocator>::propagate_on_container_move_assignment::value || get_allocator() == x.get_allocator()falseである場合、x.size()に対しても線形時間
  • (3) : size() + il.size()に対して線形時間

備考

  • (1) : 要素ブロックの容量制限を表す説明専用メンバcurrent-limitsは変更されない。
  • (2) : xの各要素ブロックを移動する場合、current-limitsxのものに設定される。

#include <hive>
#include <print>

int main()
{
  std::hive<int> h1 = {1, 2, 3};
  std::hive<int> h2;

  // コピー代入
  h2 = h1;
  std::println("h2.size() = {}", h2.size());

  // ムーブ代入
  std::hive<int> h3;
  h3 = std::move(h1);
  std::println("h3.size() = {}", h3.size());

  // 初期化子リストの代入
  std::hive<int> h4;
  h4 = {1, 2, 3, 4};
  std::println("h4.size() = {}", h4.size());
}

出力

h2.size() = 3
h3.size() = 3
h4.size() = 4

バージョン

言語

  • C++26

処理系

関連項目

参照