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

履歴 編集

function
<stop_token>

std::stop_source::operator=(C++20)

stop_source& operator=(const stop_source& r) noexcept; // (1)
stop_source& operator=(stop_source&& r) noexcept;      // (2)

概要

  • (1) : コピー代入演算子。
  • (2) : ムーブ代入演算子。

効果

戻り値

*this

例外

投げない。

#include <cassert>
#include <stop_token>

int main()
{
  std::stop_source ss1;
  std::stop_source ss2(std::nostopstate);
  std::stop_source ss3(std::nostopstate);

  assert(ss1.stop_possible() == true);
  assert(ss2.stop_possible() == false);

  assert(ss1.stop_requested() == false);
  assert(ss2.stop_requested() == false);

  // (1) コピー代入演算子
  ss2 = ss1;
  assert(ss2 == ss1);
  assert(ss1.stop_possible() == true);
  assert(ss2.stop_possible() == true);

  // (2) ムーブ代入演算子
  ss3 = std::move(ss1);
  assert(ss1.stop_possible() == false);
  assert(ss3.stop_possible() == true);

  ss2.request_stop();

  assert(ss1.stop_requested() == false);
  assert(ss2.stop_requested() == true);
  assert(ss3.stop_requested() == true);
}

出力

バージョン

言語

  • C++20

処理系