Skip to content

Commit c190380

Browse files
committed
execution: sender,sender_in,sender_to (#1384)
1 parent ef98bb0 commit c190380

File tree

4 files changed

+286
-9
lines changed

4 files changed

+286
-9
lines changed

reference/execution/execution.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ namespace std::execution {
5858
|------|------|----------------|
5959
| [`execution::scheduler`](execution/scheduler.md.nolink) | Scheduler (concept) | C++26 |
6060
61-
### Reciever
61+
### Receiver
6262
6363
| 名前 | 説明 | 対応バージョン |
6464
|------|------|----------------|
65-
| [`execution::receiver`](execution/receiver.md.nolink) | Reciever (concept) | C++26 |
66-
| [`execution::receiver_of`](execution/receiver_of.md.nolink) | 完了ハンドラ指定Reciever (concept) | C++26 |
65+
| [`execution::receiver`](execution/receiver.md.nolink) | Receiver (concept) | C++26 |
66+
| [`execution::receiver_of`](execution/receiver_of.md.nolink) | 完了ハンドラ指定Receiver (concept) | C++26 |
6767
| [`execution::set_value`](execution/set_value.md.nolink) | 値による完了関数 (customization point object) | C++26 |
6868
| [`execution::set_error`](execution/set_error.md.nolink) | エラーによる完了関数 (customization point object) | C++26 |
6969
| [`execution::set_stopped`](execution/set_stopped.md.nolink) | 停止による完了関数 (customization point object) | C++26 |
@@ -80,9 +80,9 @@ namespace std::execution {
8080
| 名前 | 説明 | 対応バージョン |
8181
|------|------|----------------|
8282
| [`execution::default_domain`](execution/default_domain.md.nolink) | デフォルト実行ドメイン (class) | C++26 |
83-
| [`execution::sender`](execution/sender.md.nolink) | Sender (concept) | C++26 |
84-
| [`execution::sender_in`](execution/sender_in.md.nolink) | 環境に対応するSender (concept) | C++26 |
85-
| [`execution::sender_to`](execution/sender_to.md.nolink) | Recieverに対応するSender (concept) | C++26 |
83+
| [`execution::sender`](execution/sender.md) | Sender型 (concept) | C++26 |
84+
| [`execution::sender_in`](execution/sender_in.md) | 指定環境で有効なSender (concept) | C++26 |
85+
| [`execution::sender_to`](execution/sender_to.md) | 指定Receiverに接続可能なSender (concept) | C++26 |
8686
| [`execution::get_completion_signatures`](execution/get_completion_signatures.md.nolink) | 完了シグネチャ取得の問い合わせオブジェクト (customization point object) | C++26 |
8787
| [`execution::completion_signatures_of_t`](execution/get_completion_signatures.md.nolink) | Senderから完了シグネチャを取得 (alias template) | C++26 |
8888
| [`execution::value_types_of_t`](execution/value_types_of_t.md.nolink) | Senderの値完了型を取得 (alias template) | C++26 |
@@ -92,7 +92,7 @@ namespace std::execution {
9292
| [`execution::transform_sender`](execution/transform_sender.md.nolink) | Senderを変換 (function template) | C++26 |
9393
| [`execution::transform_env`](execution/transform_env.md.nolink) | 問い合わせオブジェクトを変換 (function template) | C++26 |
9494
| [`execution::apply_sender`](execution/apply_sender.md.nolink) | Senderにタグ型と引数を適用 (function template) | C++26 |
95-
| [`execution::connect`](execution/connect.md.nolink) | SenderとRecieverを接続 (customization point object) | C++26 |
95+
| [`execution::connect`](execution/connect.md.nolink) | SenderとReceiverを接続 (customization point object) | C++26 |
9696
| [`execution::connect_result_t`](execution/connect_result_t.md.nolink) | `connect`結果型を取得 (alias template) | C++26 |
9797
9898
### Senderファクトリ
@@ -102,7 +102,7 @@ namespace std::execution {
102102
| [`execution::just`](execution/just.md.nolink) | 値を送信するSender (customization point object) | C++26 |
103103
| [`execution::just_error`](execution/just_error.md.nolink) | エラーを送信するSender (customization point object) | C++26 |
104104
| [`execution::just_stopped`](execution/just_stopped.md.nolink) | 停止を送信するSender (customization point object) | C++26 |
105-
| [`execution::read_env`](execution/read_env.md.nolink) | Reciever環境から構築されるSender (customization point object) | C++26 |
105+
| [`execution::read_env`](execution/read_env.md.nolink) | Receiver環境から構築されるSender (customization point object) | C++26 |
106106
| [`execution::schedule`](execution/schedule.md.nolink) | Scheduler上で実行されるSender (customization point object) | C++26 |
107107
| [`execution::schedule_result_t`](execution/schedule_result_t.md.nolink) | `schedule`結果型を取得 (alias template) | C++26 |
108108
@@ -138,7 +138,7 @@ namespace std::execution {
138138
139139
Senderコンシューマは名前空間 `std::this_thread` で定義される。
140140
141-
### Sender/Recieverユーティリティ
141+
### Sender/Receiverユーティリティ
142142
143143
| 名前 | 説明 | 対応バージョン |
144144
|------|------|----------------|
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# sender
2+
* execution[meta header]
3+
* concept[meta id-type]
4+
* std::execution[meta namespace]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std::execution {
9+
template <class Sndr>
10+
concept sender;
11+
12+
struct sender_t {}; // タグ型
13+
}
14+
```
15+
16+
## 概要
17+
`sender`は、型`Sndr`がSender型の要件を満たすことを表すコンセプトである。
18+
19+
次のいずれかのクラス型はSenderとみなせる。
20+
21+
- `sender_t`をメンバ型`Sndr::sender_concept`として定義するクラス型
22+
- [コルーチンのAwaitable型](/lang/cpp20/coroutines.md)クラス型
23+
24+
25+
## 要件
26+
説明専用コンセプト`is-sender`, `enable-sender`、説明用クラステンプレート`env-promise`を以下のように定義する。
27+
28+
```cpp
29+
template<class Sndr>
30+
concept is-sender =
31+
derived_from<typename Sndr::sender_concept, sender_t>;
32+
33+
template<class Sndr>
34+
concept enable-sender =
35+
is-sender<Sndr> ||
36+
is-awaitable<Sndr, env-promise<env<>>>;
37+
38+
template<class Env>
39+
struct env-promise : with-await-transform<env-promise<Env>> {
40+
unspecified get_return_object() noexcept;
41+
unspecified initial_suspend() noexcept;
42+
unspecified final_suspend() noexcept;
43+
void unhandled_exception() noexcept;
44+
void return_void() noexcept;
45+
coroutine_handle<> unhandled_stopped() noexcept;
46+
47+
const Env& get_env() const noexcept;
48+
};
49+
```
50+
* is-awaitable[link is-awaitable.md.nolink]
51+
* env[link env.md.nolink]
52+
* derived_from[link /reference/concepts/derived_from.md]
53+
* coroutine_handle[link /reference/coroutine/coroutine_handle.md]
54+
* unspecified[italic]
55+
56+
`sender`コンセプトは、以下のように定義される。
57+
58+
```cpp
59+
template<class Sndr>
60+
concept sender =
61+
bool(enable-sender<remove_cvref_t<Sndr>>) &&
62+
requires (const remove_cvref_t<Sndr>& sndr) {
63+
{ get_env(sndr) } -> queryable;
64+
} &&
65+
move_constructible<remove_cvref_t<Sndr>> &&
66+
constructible_from<remove_cvref_t<Sndr>, Sndr>;
67+
```
68+
* get_env[link get_env.md.nolink]
69+
* queryable[link queryable.md.nolink]
70+
* move_constructible[link /reference/concepts/move_constructible.md]
71+
* constructible_from[link /reference/concepts/constructible_from.md]
72+
73+
74+
## 備考
75+
`sender`コンセプトの制約式に現れる第1項`bool(enable-sender<...>)`は[原子制約(atomic contraint)](/lang/cpp20/concepts.md)を構成する。
76+
これによりオーバーロード解決時の優先順比較のためのにおいて`enable-sender`コンセプトの`||`を単純なOR条件とみなせ、コンパイル時の複雑な包摂関係計算コストを抑制できる。
77+
78+
79+
## 例
80+
```cpp example
81+
#include <execution>
82+
namespace ex = std::execution;
83+
84+
int main()
85+
{
86+
// 値42を送信するSender
87+
ex::sender auto sndr = ex::just(42);
88+
}
89+
```
90+
* ex::sender[color ff0000]
91+
* ex::just[link just.md.nolink]
92+
93+
### 出力
94+
```
95+
```
96+
97+
98+
## バージョン
99+
### 言語
100+
- C++26
101+
102+
### 処理系
103+
- [Clang](/implementation.md#clang): ??
104+
- [GCC](/implementation.md#gcc): ??
105+
- [ICC](/implementation.md#icc): ??
106+
- [Visual C++](/implementation.md#visual_cpp): ??
107+
108+
109+
## 関連項目
110+
- [`sender_in`](sender_in.md)
111+
- [`sender_to`](sender_to.md)
112+
- [コルーチン](/lang/cpp20/coroutines.md)
113+
114+
115+
## 参照
116+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# sender_in
2+
* execution[meta header]
3+
* concept[meta id-type]
4+
* std::execution[meta namespace]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std::execution {
9+
template<class Sndr, class Env = env<>>
10+
concept sender_in =
11+
sender<Sndr> &&
12+
queryable<Env> &&
13+
requires (Sndr&& sndr, Env&& env) {
14+
{ get_completion_signatures(std::forward<Sndr>(sndr), std::forward<Env>(env)) }
15+
-> valid-completion-signatures;
16+
};
17+
}
18+
```
19+
* env<>[link env.md.nolink]
20+
* sender[link sender.md]
21+
* queryable[link queryable.md.nolink]
22+
* get_completion_signatures[link get_completion_signatures.md.nolink]
23+
* valid-completion-signatures[link valid-completion-signatures.md.nolink]
24+
25+
## 概要
26+
`sender_in`は、[Sender型](sender.md)`Sndr`が[環境](env.md.nolink)`Env`において非同期操作を作成できること表すコンセプトである。
27+
28+
29+
## モデル
30+
説明用に`sndr`を`decltype((sndr))`が`Sndr`型となる式、`rcvr`を環境`Env`に関連付けられたReceiverと定義する。
31+
32+
また、ある完了操作の完了シグネチャが[`completion_signatures_of_t`](completion_signatures_of_t.md.nolink)`<Sndr, Env>`で取得される[`completion_signatures`](completion_signatures.md.nolink)リストに含まれるとき、`Sndr`と`Env`における許容可能完了操作(permissible completion)となる。
33+
34+
`sndr`と`rcvr`の接続後に操作状態を開始することで評価されうる完了操作が、全て許容可能完了操作(permissible completion)である場合、`Sndr`と`Env`は`sender_in<Sndr, Env>`のモデルとなる。
35+
36+
37+
## 例
38+
```cpp example
39+
#include <execution>
40+
namespace ex = std::execution;
41+
42+
int main()
43+
{
44+
ex::sender auto sndr = ex::just(42);
45+
static_assert(ex::sender_in<decltype(sndr), ex::env<>>);
46+
}
47+
```
48+
* ex::sender_in[color ff0000]
49+
* ex::sender[link sender.md]
50+
* ex::just[link just.md.nolink]
51+
* ex::env<>[link env.md.nolink]
52+
53+
### 出力
54+
```
55+
```
56+
57+
58+
## バージョン
59+
### 言語
60+
- C++26
61+
62+
### 処理系
63+
- [Clang](/implementation.md#clang): ??
64+
- [GCC](/implementation.md#gcc): ??
65+
- [ICC](/implementation.md#icc): ??
66+
- [Visual C++](/implementation.md#visual_cpp): ??
67+
68+
69+
## 関連項目
70+
- [`sender`](sender.md)
71+
- [`env`](env.md.nolink)
72+
73+
74+
## 参照
75+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# sender_to
2+
* execution[meta header]
3+
* concept[meta id-type]
4+
* std::execution[meta namespace]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std::execution {
9+
template<class Sndr, class Rcvr>
10+
concept sender_to =
11+
sender_in<Sndr, env_of_t<Rcvr>> &&
12+
receiver_of<Rcvr, completion_signatures_of_t<Sndr, env_of_t<Rcvr>>> &&
13+
requires (Sndr&& sndr, Rcvr&& rcvr) {
14+
connect(std::forward<Sndr>(sndr), std::forward<Rcvr>(rcvr));
15+
};
16+
}
17+
```
18+
* sender_in[link sender_in.md]
19+
* env_of_t[link env_of_t.md.nolink]
20+
* receiver_of[link receiver_of.md.nolink]
21+
* completion_signatures_of_t[link completion_signatures_of_t.md.nolink]
22+
* connect[link connect.md.nolink]
23+
24+
## 概要
25+
`sender_to`は、[Sender型](sender.md)`Sndr`が[Receiver型](receiver.md.nolink)`Rcvr`と接続可能であること表すコンセプトである。
26+
27+
28+
## 例
29+
```cpp example
30+
#include <print>
31+
#include <execution>
32+
namespace ex = stdexec;
33+
34+
struct ValueReceiver {
35+
using receiver_concept = ex::receiver_t;
36+
37+
void set_value(int v) noexcept
38+
{
39+
std::println("{}", v);
40+
}
41+
};
42+
43+
int main()
44+
{
45+
// 値42を送信するSender
46+
ex::sender auto sndr = ex::just(42);
47+
static_assert(ex::sender_to<decltype(sndr), ValueReceiver>);
48+
49+
// int値を受信して表示するReceiver
50+
ValueReceiver rcvr;
51+
52+
// SenderとReceiver接続後にOperationStateを開始
53+
ex::operation_state auto op = ex::connect(sndr, rcvr);
54+
ex::start(op);
55+
}
56+
```
57+
* ex::sender_to[color ff0000]
58+
* ex::just[link just.md.nolink]
59+
* ex::operation_state[link operation_state.md.nolink]
60+
* ex::connect[link connect.md.nolink]
61+
* ex::start[link start.md.nolink]
62+
63+
### 出力
64+
```
65+
42
66+
```
67+
68+
69+
## バージョン
70+
### 言語
71+
- C++26
72+
73+
### 処理系
74+
- [Clang](/implementation.md#clang): ??
75+
- [GCC](/implementation.md#gcc): ??
76+
- [ICC](/implementation.md#icc): ??
77+
- [Visual C++](/implementation.md#visual_cpp): ??
78+
79+
80+
## 関連項目
81+
- [`sender`](sender.md)
82+
- [`receiver`](receiver.md.nolink)
83+
84+
85+
## 参照
86+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)

0 commit comments

Comments
 (0)