Skip to content

Commit b8c7c50

Browse files
committed
execution: read_env (#1384)
1 parent f9534c2 commit b8c7c50

2 files changed

Lines changed: 96 additions & 2 deletions

File tree

reference/execution/execution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ namespace std::execution {
8888
| [`execution::value_types_of_t`](execution/value_types_of_t.md) | Senderの値完了シグネチャ集合から指定操作で型を生成 (alias template) | C++26 |
8989
| [`execution::error_types_of_t`](execution/error_types_of_t.md) | Senderのエラー完了シグネチャ集合から指定操作で型を生成 (alias template) | C++26 |
9090
| [`execution::sends_stopped`](execution/sends_stopped.md) | Senderが停止完了を送信しうるか否か (variable template) | C++26 |
91-
| [`execution::tag_of_t`](execution/tag_of_t.md) | Senderアルゴリズムタグを取得 (alias template) | C++26 |
91+
| [`execution::tag_of_t`](execution/tag_of_t.md) | Senderアルゴリズムタグ型を取得 (alias template) | C++26 |
9292
| [`execution::transform_sender`](execution/transform_sender.md) | Senderを変換 (function template) | C++26 |
9393
| [`execution::transform_env`](execution/transform_env.md) | 環境を変換 (function template) | C++26 |
9494
| [`execution::apply_sender`](execution/apply_sender.md) | Senderアルゴリズムを適用 (function template) | C++26 |
@@ -102,7 +102,7 @@ namespace std::execution {
102102
| [`execution::just`](execution/just.md) | 値を送信する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) | Receiver環境から構築されるSender (customization point object) | C++26 |
105+
| [`execution::read_env`](execution/read_env.md) | Receiver環境からクエリオブジェクトで値を読み取るSender (customization point object) | C++26 |
106106
| [`execution::schedule`](execution/schedule.md) | Scheduler上で実行されるSender (customization point object) | C++26 |
107107
| [`execution::schedule_result_t`](execution/schedule_result_t.md) | [`schedule`](execution/schedule.md)結果型を取得 (alias template) | C++26 |
108108
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# read_env
2+
* execution[meta header]
3+
* cpo[meta id-type]
4+
* std::execution[meta namespace]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std::execution {
9+
inline constexpr unspecified read_env{};
10+
}
11+
```
12+
* unspecified[italic]
13+
14+
## 概要
15+
`read_env`は、非同期動作の[開始(start)](start.md)時に接続先[Receiver](receiver.md)の[環境](../queryable.md)に対して[クエリオブジェクト](../queryable.md)で問い合わせ、読み取った値を[値完了関数](set_value.md)で送信するSenderファクトリである。
16+
17+
クエリオブジェクトによるReceiver環境への問い合わせは`read_env`[Sender](sender.md)の構築時ではなく、Receiverと接続されたのち非同期動作が開始されるタイミングまで遅延される。
18+
[`let_value`](let_value.md.nolink)Senderアダプタと組み合わせたり、[Sender Awaitableなコルーチン](with_awaitable_senders.md.nolink)での`co_await`式によって、[Scheduler](get_scheduler.md)や[停止トークン](../get_stop_token.md)を読み取ることができる。
19+
20+
21+
## 効果
22+
[クエリオブジェクト](../queryable.md)`q`に対して、呼び出し式`read_env(q)`は式[`make-sender`](make-sender.md)`(read_env, q)`と等価。
23+
24+
25+
### Senderアルゴリズムタグ
26+
Senderアルゴリズム動作説明用のクラステンプレート`impls-for`に対して、下記の特殊化が定義される。
27+
28+
```cpp
29+
namespace std::execution {
30+
template<>
31+
struct impls-for<decayed-typeof<read_env>> : default-impls {
32+
static constexpr auto start =
33+
[](auto query, auto& rcvr) noexcept -> void {
34+
TRY-SET-VALUE(rcvr, query(get_env(rcvr)));
35+
};
36+
};
37+
}
38+
```
39+
* decayed-typeof[link decayed-typeof.md.nolink]
40+
* impls-for[link impls-for.md]
41+
* default-impls[link impls-for.md]
42+
* get_env[link get_env.md]
43+
44+
45+
## 備考
46+
`read_env`[Senderアルゴリズムタグ型](tag_of_t.md)は未規定とされる。
47+
48+
49+
##
50+
```cpp example
51+
#include <print>
52+
#include <execution>
53+
namespace ex = std::execution;
54+
55+
int main()
56+
{
57+
ex::sender auto sndr = ex::read_env(ex::get_scheduler)
58+
| ex::let_value([](auto sch) -> ex::sender auto {
59+
// sch := sync_wait内部のScheduler
60+
return ex::starts_on(sch, std::just(42));
61+
});
62+
auto [val] = std::this_thread::sync_wait(sndr).value();
63+
std::println("{}", val);
64+
}
65+
```
66+
* ex::read_env[color ff0000]
67+
* ex::sender[link sender.md]
68+
* ex::get_scheduler[link get_scheduler.md]
69+
* ex::starts_on[link starts_on.md.nolink]
70+
* std::this_thread::sync_wait[link ../this_thread/sync_wait.md]
71+
72+
### 出力
73+
```
74+
42
75+
```
76+
77+
78+
## バージョン
79+
### 言語
80+
- C++26
81+
82+
### 処理系
83+
- [Clang](/implementation.md#clang): ??
84+
- [GCC](/implementation.md#gcc): ??
85+
- [ICC](/implementation.md#icc): ??
86+
- [Visual C++](/implementation.md#visual_cpp): ??
87+
88+
89+
## 関連項目
90+
- [`execution::get_env`](read_env.md)
91+
92+
93+
## 参照
94+
- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html)

0 commit comments

Comments
 (0)