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

履歴 編集

class
<stop_token>

std::stop_source(C++20)

namespace std {
  class stop_source;
}

概要

クラスstop_sourceは、停止状態をstop_tokenと共有所有し、停止要求を作成するためのインターフェースを提供する。

stop_sourcestoppable-sourcecopyableequality_comparableswappableのモデルである。

メンバ関数

名前 説明 対応バージョン
(constructor) コンストラクタ C++20
(destructor) デストラクタ C++20
operator= 代入演算子 C++20
swap 別のstop_sourceと交換する C++20
get_token 自身と停止状態を共有するstop_tokenを返す C++20
stop_possible 停止要求を作成可能どうかを取得する C++20
stop_requested 停止要求を作成したかどうかを取得する C++20
request_stop 停止要求を作成する C++20

非メンバ関数

名前 説明 対応バージョン
operator== 等値演算子 C++20
operator!= 非等値演算子 C++20
swap 2つのstop_sourceオブジェクトを入れ替える C++20

#include <cassert>
#include <stop_token>

int main()
{
  std::stop_source ss;
  std::stop_token st = ss.get_token();

  bool invoked = false;
  std::stop_callback cb {st, [&] { invoked = true; }};

  assert(st.stop_requested() == false);
  assert(invoked == false);

  ss.request_stop();

  assert(st.stop_requested() == true);
  assert(invoked == true);
}

出力

バージョン

言語

  • C++20

処理系

関連項目

参照