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

履歴 編集

function
<stop_token>

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

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

概要

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

効果

戻り値

*this

例外

投げない。

#include <cassert>
#include <stop_token>

int main()
{
  std::stop_source ss;

  std::stop_token st1 = ss.get_token();
  std::stop_token st2;
  std::stop_token st3;

  assert(st1.stop_possible() == true);
  assert(st2.stop_possible() == false);

  assert(st1.stop_requested() == false);
  assert(st2.stop_requested() == false);

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

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

  ss.request_stop();

  assert(st1.stop_requested() == false);
  assert(st2.stop_requested() == true);
  assert(st3.stop_requested() == true);
}

出力

バージョン

言語

  • C++20

処理系