|
| 1 | +# inplace_stop_callback |
| 2 | +* stop_token[meta header] |
| 3 | +* std[meta namespace] |
| 4 | +* class template[meta id-type] |
| 5 | +* cpp26[meta cpp] |
| 6 | + |
| 7 | +```cpp |
| 8 | +namespace std { |
| 9 | + template<class CallbackFn> |
| 10 | + class inplace_stop_callback; |
| 11 | +} |
| 12 | +``` |
| 13 | +
|
| 14 | +## 概要 |
| 15 | +`inplace_stop_callback`クラステンプレートは、停止要求が作成された際に呼び出されるコールバックを表す。 |
| 16 | +
|
| 17 | +
|
| 18 | +## 適格要件 |
| 19 | +テンプレート引数`CallbackFn`が[`invocable`](/reference/concepts/invokable.md.nolink)および[`destructible`](/reference/concepts/destructible.md)を満たすこと。 |
| 20 | +
|
| 21 | +
|
| 22 | +## メンバ関数 |
| 23 | +
|
| 24 | +| 名前 | 説明 | 対応バージョン | |
| 25 | +|------|------|-------| |
| 26 | +| [`(constructor)`](inplace_stop_callback/op_constructor.md)| コンストラクタ | C++26 | |
| 27 | +| [`(destructor)`](inplace_stop_callback/op_destructor.md) | デストラクタ | C++26 | |
| 28 | +| `operator=(const inplace_stop_callback&) = delete;` | 代入演算子 | C++26 | |
| 29 | +| `operator=(inplace_stop_callback&&) = delete;` | 代入演算子 | C++26 | |
| 30 | +
|
| 31 | +## メンバ型 |
| 32 | +
|
| 33 | +| 名前 | 説明 | 対応バージョン | |
| 34 | +|------|------|-------| |
| 35 | +| `callback_type` | `CallbackFn` | C++26 | |
| 36 | +
|
| 37 | +## 推論補助 |
| 38 | +
|
| 39 | +| 名前 | 説明 | 対応バージョン | |
| 40 | +|------|------|-------| |
| 41 | +| [`(deduction_guide)`](inplace_stop_callback/op_deduction_guide.md) | クラステンプレートの推論補助 | C++26 | |
| 42 | +
|
| 43 | +
|
| 44 | +## 例 |
| 45 | +```cpp example |
| 46 | +#include <cassert> |
| 47 | +#include <stop_token> |
| 48 | +#include <string> |
| 49 | +
|
| 50 | +int main() |
| 51 | +{ |
| 52 | + std::string msg; |
| 53 | +
|
| 54 | + std::inplace_stop_source ss; |
| 55 | + std::inplace_stop_token st = ss.get_token(); |
| 56 | + std::inplace_stop_callback cb1(st, [&] { msg += "hello"; }); |
| 57 | +
|
| 58 | + assert(msg == ""); |
| 59 | +
|
| 60 | + ss.request_stop(); |
| 61 | +
|
| 62 | + // 停止要求が作成される前に登録されていたコールバック関数は、 |
| 63 | + // 停止要求が作成された際にその中で呼び出される |
| 64 | + assert(msg == "hello"); |
| 65 | +
|
| 66 | + std::inplace_stop_callback cb2(st, [&] { msg += " world"; }); |
| 67 | +
|
| 68 | + // 停止要求が作成されたあとに登録されたコールバック関数は、 |
| 69 | + // std::inplace_stop_callback クラスのコンストラクタの中で即座に呼び出される |
| 70 | + assert(msg == "hello world"); |
| 71 | +} |
| 72 | +``` |
| 73 | +* std::inplace_stop_callback[color ff0000] |
| 74 | +* std::inplace_stop_token[link inplace_stop_token.md] |
| 75 | +* std::inplace_stop_source[link inplace_stop_source.md] |
| 76 | +* request_stop()[link inplace_stop_source/request_stop.md] |
| 77 | +* get_token()[link inplace_stop_source/get_token.md] |
| 78 | + |
| 79 | +### 出力 |
| 80 | +``` |
| 81 | +``` |
| 82 | + |
| 83 | +## バージョン |
| 84 | +### 言語 |
| 85 | +- C++26 |
| 86 | + |
| 87 | + |
| 88 | +### 処理系 |
| 89 | +- [Clang](/implementation.md#clang): ?? |
| 90 | +- [GCC](/implementation.md#gcc): ?? |
| 91 | +- [ICC](/implementation.md#icc): ?? |
| 92 | +- [Visual C++](/implementation.md#visual_cpp): ?? |
| 93 | + |
| 94 | + |
| 95 | +## 関連項目 |
| 96 | +- [`inplace_stop_token`](inplace_stop_token.md) |
| 97 | +- [`inplace_stop_source`](inplace_stop_source.md) |
| 98 | + |
| 99 | + |
| 100 | +## 参照 |
| 101 | +- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html) |
0 commit comments