- stop_token[meta header]
- std[meta namespace]
- class template[meta id-type]
- cpp26[meta cpp]
namespace std {
template<class CallbackFn>
class inplace_stop_callback;
}
inplace_stop_callbackクラステンプレートは、停止要求が作成された際に呼び出されるコールバックを表す。
テンプレート引数CallbackFnがinvocableおよびdestructibleを満たすこと。
| 名前 |
説明 |
対応バージョン |
(constructor) |
コンストラクタ |
C++26 |
(destructor) |
デストラクタ |
C++26 |
operator=(const inplace_stop_callback&) = delete; |
代入演算子 |
C++26 |
operator=(inplace_stop_callback&&) = delete; |
代入演算子 |
C++26 |
| 名前 |
説明 |
対応バージョン |
callback_type |
CallbackFn |
C++26 |
#include <cassert>
#include <stop_token>
#include <string>
int main()
{
std::string msg;
std::inplace_stop_source ss;
std::inplace_stop_token st = ss.get_token();
std::inplace_stop_callback cb1(st, [&] { msg += "hello"; });
assert(msg == "");
ss.request_stop();
// 停止要求が作成される前に登録されていたコールバック関数は、
// 停止要求が作成された際にその中で呼び出される
assert(msg == "hello");
std::inplace_stop_callback cb2(st, [&] { msg += " world"; });
// 停止要求が作成されたあとに登録されたコールバック関数は、
// std::inplace_stop_callback クラスのコンストラクタの中で即座に呼び出される
assert(msg == "hello world");
}
- std::inplace_stop_callback[color ff0000]
- std::inplace_stop_token[link inplace_stop_token.md]
- std::inplace_stop_source[link inplace_stop_source.md]
- request_stop()[link inplace_stop_source/request_stop.md]
- get_token()[link inplace_stop_source/get_token.md]