namespace std {
class stop_source;
}
概要
クラスstop_source
は、停止状態をstop_token
と共有所有し、停止要求を作成するためのインターフェースを提供する。
stop_source
はstoppable-source
、copyable
、equality_comparable
、swappable
のモデルである。
メンバ関数
名前 | 説明 | 対応バージョン |
---|---|---|
(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
処理系
- Clang: ??
- GCC: ??
- ICC: ??
- Visual C++: ??