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

履歴 編集

function
<thread>

std::thread::operator=(C++11)

// コピー
thread& operator=(const thread&) = delete;

// ムーブ
thread& operator=(thread&& x) noexcept;

概要

threadオブジェクトはムーブ代入可能/コピー代入不可。

効果

ムーブ代入演算子呼び出し時点でthisにスレッドが関連付けられている場合、std::terminate()を呼び出してプログラムを異常終了する。そうでなければxからthisへのムーブ代入を行う。

事後条件

ムーブ前にxと関連付けられていたスレッドはthisに関連付けられる。ムーブ後のxは何も指さない空のthreadオブジェクトとなる。

戻り値

*thisを返す。

#include <thread>
#include <cassert>

int main()
{
  std::thread t1([]{ /*...*/ });
  std::thread t2;
  assert(t1.joinable() && !t2.joinable());

  // t1からt2へムーブ代入
  t2 = std::move(t1);
  assert(!t1.joinable() && t2.joinable());

  t2.join();
}

出力

バージョン

言語

  • C++11

処理系

参照