|
| 1 | +# sync-wait-receiver |
| 2 | +* execution[meta header] |
| 3 | +* class template[meta id-type] |
| 4 | +* std::this_thread[meta namespace] |
| 5 | +* cpp26[meta cpp] |
| 6 | + |
| 7 | +```cpp |
| 8 | +namespace std::this_thread { |
| 9 | + template<class Sndr> |
| 10 | + struct sync-wait-receiver { // exposition only |
| 11 | + using receiver_concept = execution::receiver_t; |
| 12 | + sync-wait-state<Sndr>* state; // exposition only |
| 13 | + |
| 14 | + template<class... Args> |
| 15 | + void set_value(Args&&... args) && noexcept; |
| 16 | + |
| 17 | + template<class Error> |
| 18 | + void set_error(Error&& err) && noexcept; |
| 19 | + |
| 20 | + void set_stopped() && noexcept; |
| 21 | + |
| 22 | + sync-wait-env get_env() const noexcept { return {&state->loop}; } |
| 23 | + }; |
| 24 | + |
| 25 | + template<class Sndr> |
| 26 | + struct sync-wait-state { // exposition only |
| 27 | + execution::run_loop loop; // exposition only |
| 28 | + exception_ptr error; // exposition only |
| 29 | + sync-wait-result-type<Sndr> result; // exposition only |
| 30 | + }; |
| 31 | +} |
| 32 | +``` |
| 33 | +* execution::receiver_t[link ../execution/receiver.md] |
| 34 | +* execution::run_loop[link ../execution/run_loop.md] |
| 35 | +* exception_ptr[link /reference/exception/exception_ptr.md] |
| 36 | +* sync-wait-result-type[link sync_wait.md] |
| 37 | +
|
| 38 | +## 概要 |
| 39 | +`sync-wait-receiver`および`sync-wait-state`は、実行制御ライブラリの仕様定義で用いられる説明専用のクラステンプレートである。 |
| 40 | +
|
| 41 | +Senderコンシューマ[`sync_wait`](sync_wait.md)動作において[Sender](../execution/sender.md)と[接続(connect)](../execution/connect.md)する[Receiver](../execution/receiver.md)、同Receiverの内部状態として利用される。 |
| 42 | +
|
| 43 | +
|
| 44 | +### メンバ関数 `set_value` |
| 45 | +```cpp |
| 46 | +template<class... Args> |
| 47 | +void set_value(Args&&... args) && noexcept; |
| 48 | +``` |
| 49 | + |
| 50 | +効果 : 下記と等価 |
| 51 | + |
| 52 | +```cpp |
| 53 | +try { |
| 54 | + state->result.emplace(std::forward<Args>(args)...); |
| 55 | +} catch (...) { |
| 56 | + state->error = current_exception(); |
| 57 | +} |
| 58 | +state->loop.finish(); |
| 59 | +``` |
| 60 | +* emplace[link /reference/optional/optional/emplace.md] |
| 61 | +* current_exception()[link /reference/exception/current_exception.md] |
| 62 | +* finish()[link ../execution/run_loop/finish.md] |
| 63 | + |
| 64 | + |
| 65 | +### メンバ関数 `set_error` |
| 66 | +```cpp |
| 67 | +template<class Error> |
| 68 | +void set_error(Error&& err) && noexcept |
| 69 | +``` |
| 70 | +
|
| 71 | +説明用の式`err`に対して`decltype((err))`を型`Err`としたとき、式`AS-EXCEPT-PTR(err)`を下記の通り定義する。 |
| 72 | +
|
| 73 | +- [`decay_t`](/reference/type_traits/decay.md)`<Err>`が[`exception_ptr`](/reference/exception/exception_ptr.md)型と等しければ、`err`となる。このとき、事前条件として`!err == false`を満たすこと。 |
| 74 | +- そうではなく、[`decay_t`](/reference/type_traits/decay.md)`<Err>`が[`error_code`](/reference/system_error/error_code.md)型と等しければ、[`make_exception_ptr`](/reference/exception/make_exception_ptr.md)`(`[`system_error`](/reference/system_error/system_error.md)`(err))`となる。 |
| 75 | +- そうでなければ、[`make_exception_ptr`](/reference/exception/make_exception_ptr.md)`(err)`となる。 |
| 76 | +
|
| 77 | +効果 : 下記と等価 |
| 78 | +
|
| 79 | +```cpp |
| 80 | +state->error = AS-EXCEPT-PTR(std::forward<Error>(err)); |
| 81 | +state->loop.finish(); |
| 82 | +``` |
| 83 | +* finish()[link ../execution/run_loop/finish.md] |
| 84 | + |
| 85 | + |
| 86 | +### メンバ関数 `set_stopped` |
| 87 | +```cpp |
| 88 | +void set_stopped() && noexcept; |
| 89 | +``` |
| 90 | + |
| 91 | +効果 : `state->loop.`[`finish()`](../execution/run_loop/finish.md)と等価。 |
| 92 | + |
| 93 | + |
| 94 | +## バージョン |
| 95 | +### 言語 |
| 96 | +- C++26 |
| 97 | + |
| 98 | + |
| 99 | +## 関連項目 |
| 100 | +- [`this_thread::sync_wait`](sync_wait.md) |
| 101 | +- [`execution::run_loop`](../execution/run_loop.md) |
| 102 | + |
| 103 | + |
| 104 | +## 参照 |
| 105 | +- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html) |
0 commit comments