Skip to content

Commit c75607b

Browse files
committed
stop_token: inplace_stop_callback全メンバ (#1384)
- stop_callback/op_constructor P2300R10追従 - stop_callback/op_destructor P2300R10追従
1 parent 43651f2 commit c75607b

13 files changed

Lines changed: 301 additions & 38 deletions

reference/stop_token.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
`<stop_token>`ヘッダは、マルチスレッド処理や非同期処理おける停止要求の状態 `停止状態` を扱うクラスを定義する。
66

77
- [`stop_token`](stop_token/stop_token.md), [`stop_source`](stop_token/stop_source.md), [`stop_callback`](stop_token/stop_callback.md)は停止状態を共有所有する。最後に破棄されたオブジェクトが停止状態を自動的に解放する。
8-
- [`inplace_stop_source`](stop_token/inplace_stop_source.md)は停止状態をメンバとして直接所有する。[`inplace_stop_token`](stop_token/inplace_stop_token.md)[`inplace_stop_callback`](stop_token/inplace_stop_callback.md.nolink)は停止状態の所有には関与しない。
8+
- [`inplace_stop_source`](stop_token/inplace_stop_source.md)は停止状態をメンバとして直接所有する。[`inplace_stop_token`](stop_token/inplace_stop_token.md)[`inplace_stop_callback`](stop_token/inplace_stop_callback.md)は停止状態の所有には関与しない。
99

1010

1111
## コンセプト
@@ -22,9 +22,9 @@
2222
| [`stop_callback`](stop_token/stop_callback.md)| [`stop_source`](stop_token/stop_source.md)停止要求に応じて呼び出されるコールバック (class template) | C++20 |
2323
| [`nostopstate`](stop_token/nostopstate.md) | 停止状態を扱わない[`stop_source`](stop_token/stop_source.md)構築用タグ (class) | C++20 |
2424
| [`never_stop_token`](stop_token/never_stop_token.md) | 停止不可能な停止トークン (class) | C++26 |
25-
| [`inplace_stop_token`](stop_token/inplace_stop_token.md) | [`inplace_stop_source`](stop_token/inplace_stop_source.md)の停止トークン (class) | C++26 |
26-
| [`inplace_stop_source`](stop_token/inplace_stop_source.md) | 停止状態を直接所有する停止要求インタフェース (class) | C++26 |
27-
| [`inplace_stop_callback`](stop_token/inplace_stop_callback.md.nolink) | [`inplace_stop_source`](stop_token/inplace_stop_source.md)停止要求に応じて呼び出されるコールバック (class template) | C++26 |
25+
| [`inplace_stop_token`](stop_token/inplace_stop_token.md) | [`inplace_stop_source`](stop_token/inplace_stop_source.md)の停止トークン (class) | C++26 |
26+
| [`inplace_stop_source`](stop_token/inplace_stop_source.md) | 停止状態を直接所有する停止要求インタフェース (class) | C++26 |
27+
| [`inplace_stop_callback`](stop_token/inplace_stop_callback.md) | [`inplace_stop_source`](stop_token/inplace_stop_source.md)停止要求に応じて呼び出されるコールバック (class template) | C++26 |
2828
| [`stop_callback_for_t`](stop_token/stop_callback_for_t.md) | 対応するコールバック型を取得 (alias template) | C++26 |
2929

3030

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# コンストラクタ
2+
* stop_token[meta header]
3+
* std[meta namespace]
4+
* inplace_stop_callback[meta class]
5+
* function[meta id-type]
6+
* cpp26[meta cpp]
7+
8+
```cpp
9+
template<class Initializer>
10+
explicit inplace_stop_callback(inplace_stop_token st, Initializer&& init)
11+
noexcept(is_nothrow_constructible_v<CallbackFn, Initializer>); // (1)
12+
13+
inplace_stop_callback(const inplace_stop_callback&) = delete; // (2)
14+
inplace_stop_callback(inplace_stop_callback&&) = delete; // (3)
15+
```
16+
* inplace_stop_token[link ../inplace_stop_token.md]
17+
* is_nothrow_constructible_v[link /reference/type_traits/is_nothrow_constructible.md]
18+
19+
## 概要
20+
- (1) : [`inplace_stop_token`](../inplace_stop_token.md)を受け取り、その`inplace_stop_token`が参照する停止状態への停止要求に応じて呼び出されるコールバックを登録する。
21+
- (2) : コピーコンストラクタ。コピー不可。
22+
- (3) : ムーブコンストラクタ。ムーブ不可。
23+
24+
25+
## テンプレートパラメータ制約
26+
クラステンプレートのテンプレート引数`CallbackFn`とコンストラクタのテンプレート引数`Initializer`は[`constructible_from`](/reference/concepts/constructible_from.md)`<CallbackFn, Initializer>`制約を満たすこと。
27+
28+
29+
## 効果
30+
説明専用のメンバ変数`callback-fn`を[`std::forward`](/reference/utility/forward.md)`<CallbackFn>(init)`で初期化し、[停止可能コールバック登録](../stoppable_token.md)を実行する。
31+
32+
33+
## 例外
34+
説明専用のメンバ変数`callback-fn`を`init`で初期化する際に例外が発生する場合は、その例外を送出する。
35+
36+
37+
## バージョン
38+
### 言語
39+
- C++26
40+
41+
### 処理系
42+
- [Clang](/implementation.md#clang): ??
43+
- [GCC](/implementation.md#gcc): ??
44+
- [ICC](/implementation.md#icc): ??
45+
- [Visual C++](/implementation.md#visual_cpp): ??
46+
47+
48+
## 参照
49+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# 推論補助
2+
* stop_token[meta header]
3+
* std[meta namespace]
4+
* inplace_stop_callback[meta class]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std {
9+
template <class CallbackFn>
10+
inplace_stop_callback(inplace_stop_token, CallbackFn) -> inplace_stop_callback<CallbackFn>;
11+
}
12+
```
13+
* inplace_stop_token[link ../inplace_stop_token.md]
14+
15+
## 概要
16+
[`inplace_stop_callback`](../inplace_stop_callback.md)クラステンプレートの型推論補助。
17+
18+
## 例
19+
```cpp example
20+
#include <stop_token>
21+
#include <type_traits>
22+
23+
struct X {
24+
void operator()() {}
25+
};
26+
27+
int main()
28+
{
29+
X x;
30+
std::inplace_stop_token st;
31+
std::inplace_stop_callback cb { st, x };
32+
33+
static_assert(std::is_same_v<decltype(cb)::callback_type, X>);
34+
}
35+
```
36+
* std::inplace_stop_token[link ../inplace_stop_token.md]
37+
* std::inplace_stop_callback[link ../inplace_stop_callback.md]
38+
39+
### 出力
40+
```
41+
```
42+
43+
44+
## バージョン
45+
### 言語
46+
- C++26
47+
48+
### 処理系
49+
- [Clang](/implementation.md#clang): ??
50+
- [GCC](/implementation.md#gcc): ??
51+
- [ICC](/implementation.md#icc): ??
52+
- [Visual C++](/implementation.md#visual_cpp): ??
53+
54+
## 関連項目
55+
- [C++17 クラステンプレートのテンプレート引数推論](/lang/cpp17/type_deduction_for_class_templates.md)
56+
57+
## 参照
58+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# デストラクタ
2+
* stop_token[meta header]
3+
* std[meta namespace]
4+
* inplace_stop_callback[meta class]
5+
* function[meta id-type]
6+
* cpp26[meta cpp]
7+
8+
```cpp
9+
~inplace_stop_callback();
10+
```
11+
12+
## 効果
13+
[停止可能コールバック登録解除](../stoppable_token.md)を実行する。
14+
15+
16+
## バージョン
17+
### 言語
18+
- C++26
19+
20+
### 処理系
21+
- [Clang](/implementation.md#clang): ??
22+
- [GCC](/implementation.md#gcc): ??
23+
- [ICC](/implementation.md#icc): ??
24+
- [Visual C++](/implementation.md#visual_cpp): ??
25+
26+
27+
## 参照
28+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)

reference/stop_token/inplace_stop_source.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int main()
5858
```
5959
* std::inplace_stop_source[color ff0000]
6060
* std::inplace_stop_token[link inplace_stop_token.md]
61-
* std::inplace_stop_callback[link inplace_stop_callback.md.nolink]
61+
* std::inplace_stop_callback[link inplace_stop_callback.md]
6262
* stop_requested()[link inplace_stop_token/stop_requested.md]
6363
* request_stop()[link inplace_stop_source/request_stop.md]
6464
* get_token()[link inplace_stop_source/get_token.md]
@@ -81,7 +81,7 @@ int main()
8181

8282
## 関連項目
8383
- [`inplace_stop_token`](inplace_stop_token.md)
84-
- [`inplace_stop_callback`](inplace_stop_callback.md.nolink)
84+
- [`inplace_stop_callback`](inplace_stop_callback.md)
8585

8686

8787
## 参照

reference/stop_token/inplace_stop_token.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int main()
7474

7575
## 関連項目
7676
- [`inplace_stop_source`](inplace_stop_source.md)
77-
- [`inplace_stop_callback`](inplace_stop_callback.md.nolink)
77+
- [`inplace_stop_callback`](inplace_stop_callback.md)
7878

7979

8080
## 参照

reference/stop_token/inplace_stop_token/callback_type.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
template<class CallbackFn>
1010
using callback_type = inplace_stop_callback<CallbackFn>;
1111
```
12-
* inplace_stop_callback[link ../inplace_stop_callback.md.nolink]
12+
* inplace_stop_callback[link ../inplace_stop_callback.md]
1313

1414
## 概要
1515
`inplace_stop_token`に対応するコールバック型。

reference/stop_token/stop_callback.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ namespace std {
1414
## 概要
1515
`stop_callback`クラステンプレートは、停止要求が作成された際に呼び出されるコールバックを表す。
1616
17+
18+
## 適格要件
19+
テンプレート引数`CallbackFn`が[`invocable`](/reference/concepts/invokable.md.nolink)および[`destructible`](/reference/concepts/destructible.md)を満たすこと。
20+
21+
1722
## メンバ関数
1823
1924
| 名前 | 説明 | 対応バージョン |
@@ -35,11 +40,6 @@ namespace std {
3540
|------|------|-------|
3641
| [`(deduction_guide)`](stop_callback/op_deduction_guide.md) | クラステンプレートの推論補助 | C++20 |
3742
38-
## 適格要件
39-
テンプレート引数の`CallbackFn`は[`invocable`](/reference/concepts/invokable.md.nolink)と[`destructible`](/reference/concepts/destructible.md)制約を満たさなければならい。
40-
41-
## 事前条件
42-
テンプレート引数の`CallbackFn`は[`invocable`](/reference/concepts/invokable.md.nolink)と[`destructible`](/reference/concepts/destructible.md)制約を満たさなければならい。
4343
4444
## 例
4545
```cpp example
@@ -91,3 +91,11 @@ int main()
9191
- [ICC](/implementation.md#icc): ??
9292
- [Visual C++](/implementation.md#visual_cpp): ??
9393

94+
95+
## 関連項目
96+
- [`stop_token`](stop_token.md)
97+
- [`stop_source`](stop_source.md)
98+
99+
100+
## 参照
101+
- [P0660R10 Stop token and joining thread](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0660r10.pdf)

0 commit comments

Comments
 (0)