最終更新日時(UTC):
が更新

履歴 編集

function
<inplace_vector>

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

constexpr inplace_vector& operator=(const inplace_vector& other); // (1) C++26

constexpr inplace_vector& operator=(inplace_vector&& other)
  noexcept(N == 0 || (is_nothrow_move_assignable_v<T> &&
                      is_nothrow_move_constructible_v<T>));       // (2) C++26

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

概要

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

効果

  • (1) : otherの全ての要素を*thisにコピーする。*thisの既存の要素は破棄される。
  • (2) : otherの全ての要素を*thisにムーブする。*thisの既存の要素は破棄される。
  • (3) : 初期化子リストilの全ての要素を*thisにコピーする。*thisの既存の要素は破棄される。

例外

  • (3) : ilの要素数がNを超える場合、bad_alloc例外を送出する。

戻り値

*this

計算量

  • (1) : 全要素のデストラクタ呼び出しとコピーを行うために、線形時間
  • (2) : 全要素のデストラクタ呼び出しとムーブを行うために、線形時間
  • (3) : 全要素のデストラクタ呼び出しとコピーを行うために、線形時間

#include <cassert>
#include <inplace_vector>
#include <utility>

int main()
{
  // コピー代入
  {
    std::inplace_vector<int, 5> v1 = {1, 2, 3};
    std::inplace_vector<int, 5> v2;
    v2 = v1;
    assert(v1 == v2);
  }

  // ムーブ代入
  {
    std::inplace_vector<int, 5> v1 = {1, 2, 3};
    std::inplace_vector<int, 5> v2;
    auto v1_copy = v1;
    v2 = std::move(v1);
    assert(v2 == v1_copy);
  }

  // 初期化子リストからのコピー代入
  {
    std::inplace_vector<int, 5> iv;
    iv = {1, 2, 3};
    assert(iv.size() == 3);
  }
}

出力

バージョン

言語

  • C++26

処理系

参照