Skip to content

Commit e7aa9c8

Browse files
committed
execution/associate: 説明増補,例示修正 (#1510)
1 parent 5ee5356 commit e7aa9c8

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

reference/execution/execution/associate.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ namespace std::execution {
1818
1919
`associate`は[パイプ可能Senderアダプタオブジェクト](sender_adaptor_closure.md)であり、パイプライン記法をサポートする。
2020
21+
`associate`アルゴリズムが返す関連Sender(associate-sender)は、[非同期スコープトークン](scope_token.md)を介した関連付け試行(`try_associate`)の結果に応じてassociated/unassociatedいずれかの状態となり、入力Senderの動作を継承したうえで下記のように振る舞う。
22+
23+
- associated状態
24+
- 関連Senderは入力Senderと同じ完了シグネチャを持ち、関連Senderとの[接続(connect)](connect.md)や[開始(start)](start.md)によって入力Senderとの接続や開始が行われる。
25+
- 関連Senderオブジェクトが破棄、もしくは接続後の[Operation State](operation_state.md)が破棄されたとき、関連付けを解除する。
26+
- [非同期スコープトークン](scope_token.md)の`wrap`メンバ関数で追加される処理を行う。
27+
- unassociated状態 :
28+
- 入力Senderは破棄され、[接続(connect)](connect.md)も[開始(start)](start.md)もされない。
29+
- 関連Senderは[set_stopped](set_stopped.md)のみで完了する。
30+
31+
associated状態の関連Senderに対する[接続(connect)](connect.md)操作は、下記いずれかの結果となる。
32+
33+
- 右辺値接続(rvalue connected)のとき、入力Senderとの関連付けは[Operation State](operation_state.md)へ移動する。
34+
- 左辺値接続(lvalue connected)のとき、[Operation State](operation_state.md)は非同期スコープとの新たな関連付けを必要とするため、[非同期スコープトークン](scope_token.md)の`try_associate`を呼び出して下記のいずれかの結果となる。
35+
- 新たな関連付けに成功する(戻り値が`true`)。
36+
- 関連付けに失敗し(戻り値が`false`)、[Operation State](operation_state.md)はunassociated状態の関連Senderから構築されたかのように振る舞う([開始(start)](start.md)操作により即時で[停止完了](set_stopped.md)する)。
37+
- 例外送出によって接続操作に失敗する。
38+
2139
2240
## 効果
2341
説明用の式`sndr`と`token`に対して、`decltype((sndr))`が[`sender`](sender.md)を満たさない、もしくは[`remove_cvref_t`](/reference/type_traits/remove_cvref.md)`<decltype((token))>`が[`scope_token`](scope_token.md)を満たさないとき、呼び出し式`associate(sndr, token)`は不適格となる。
@@ -47,10 +65,10 @@ namespace std::execution {
4765
static constexpr auto start = see below; // exposition only
4866

4967
template<class Sndr, class... Env>
50-
static consteval void check-types() { // exposition only
51-
using associate_data_t = remove_cvref_t<data-type<Sndr>>;
52-
using child_type_t = typename associate_data_t::wrap-sender;
53-
(void)get_completion_signatures<child_type_t, FWD-ENV-T(Env)...>();
68+
static consteval void check-types() { // exposition only
69+
using associate_data_t = remove_cvref_t<data-type<Sndr>>;
70+
using child_type_t = typename associate_data_t::wrap-sender;
71+
(void)get_completion_signatures<child_type_t, FWD-ENV-T(Env)...>();
5472
}
5573
};
5674
}
@@ -190,6 +208,7 @@ namespace std::execution {
190208
* is_nothrow_copy_constructible_v[link /reference/type_traits/is_nothrow_copy_constructible.md]
191209
* is_nothrow_move_constructible_v[link /reference/type_traits/is_nothrow_move_constructible.md]
192210
* optional[link /reference/optional/optional.md]
211+
* reset()[link /reference/optional/optional/reset.md]
193212
194213
`associate-data`型のオブジェクト`a`に対して、関連付けが正常に行われかつ`a`により所有される場合に限って、`a.sndr.`[`has_value()`](/reference/optional/optional/has_value.md)は`true`となる。
195214
@@ -243,26 +262,39 @@ Senderアルゴリズム構築時および[Receiver](receiver.md)接続時に、
243262
## 例
244263
```cpp example
245264
#include <execution>
265+
#include <print>
246266
namespace ex = std::execution;
247267
248268
int main()
249269
{
270+
// 非同期スコープを定義
250271
ex::counting_scope scope;
272+
273+
// Senderと非同期スコープを関連付け
251274
ex::sender auto sndr =
252275
ex::just(42)
253276
| ex::associate(scope.get_token());
254277
255-
std::this_thread::sync_wait(sndr);
278+
// タスク開始と完了待機
279+
auto result = std::this_thread::sync_wait(std::move(sndr));
280+
std::println("value={}", *result);
281+
282+
// 非同期スコープの合流待機
283+
std::this_thread::sync_wait(scope.join());
256284
}
257285
```
258286
* ex::associate[color ff0000]
259-
* ex::counting_scope[link counting_scope.md]
260-
* ex::just[link just.md]
261287
* ex::sender[link sender.md]
288+
* ex::just[link just.md]
289+
* ex::counting_scope[link counting_scope.md]
290+
* get_token()[link counting_scope/get_token.md]
291+
* join()[link counting_scope/join.md]
262292
* std::this_thread::sync_wait[link ../this_thread/sync_wait.md]
293+
* std::move[link /reference/utility/move.md]
263294

264295
### 出力
265296
```
297+
value=42
266298
```
267299

268300

reference/execution/execution/scope_token.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ int main()
5050
```
5151
* ex::scope_token[color ff0000]
5252
* ex::counting_scope[link counting_scope.md]
53+
* get_token()[link counting_scope/get_token.md]
5354

5455
### 出力
5556
```

0 commit comments

Comments
 (0)