|
| 1 | +# get_completion_scheduler |
| 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 | + template<class CPO> |
| 10 | + struct get_completion_scheduler_t { unspecified }; |
| 11 | + |
| 12 | + template<class CPO> |
| 13 | + constexpr get_completion_scheduler_t<CPO> get_completion_scheduler{}; |
| 14 | + } |
| 15 | +``` |
| 16 | +* unspecified[italic] |
| 17 | +
|
| 18 | +## 概要 |
| 19 | +`get_completion_scheduler<completion-tag>`は、[Sender](sender.md)の[属性](get_env.md)から指定完了タグに関連付けられた完了Schedulerを取得する[クエリオブジェクト](../queryable.md)である。 |
| 20 | +完了タグ`completion-tag`には、[`set_value_t`](set_value.md), [`set_error_t`](set_error.md), [`set_stopped_t`](set_stopped.md)のいずれかを指定する。 |
| 21 | +
|
| 22 | +コア定数式[`forwarding_query`](forwarding_query.md.nolink)`(get_completion_scheduler<completion-tag>)`は`true`値を返す。 |
| 23 | +
|
| 24 | +
|
| 25 | +### 完了Scheduler |
| 26 | +完了Scheduler(completion scheduler)は、非同期操作の完了操作を実行するための実行リソース(例:CPUスレッド)と関連付けられた[Scheduler](scheduler.md)である。 |
| 27 | +
|
| 28 | +非同期操作の完了操作は、下記いずれかの完了関数呼び出しが該当する。 |
| 29 | +
|
| 30 | +- 値完了関数 [`execution::set_value`](set_value.md) |
| 31 | +- エラー完了関数 [`execution::set_error`](set_error.md) |
| 32 | +- 停止完了関数 [`execution::set_stopped`](set_stopped.md) |
| 33 | +
|
| 34 | +
|
| 35 | +## 効果 |
| 36 | +呼び出し式`get_completion_scheduler<completion-tag>(q)`は下記と等価であり、式が適格ならば[`scheduler`](scheduler.md)を満たす型の値となる。 |
| 37 | +
|
| 38 | +- 引数`q`がconst修飾された`cq`を用いて、式`cq.query(get_completion_scheduler<completion-tag>)`が適格であればその値。 |
| 39 | +- そうでなければ、呼び出し式は不適格となる。 |
| 40 | +
|
| 41 | +
|
| 42 | +## 例外 |
| 43 | +投げない |
| 44 | +
|
| 45 | +
|
| 46 | +## カスタマイゼーションポイント |
| 47 | +const修飾[クエリ可能オブジェクト](../queryable.md)`cq`に対して式`cq.query(get_completion_scheduler<completion-tag>)`が呼び出される。 |
| 48 | +このとき、`noexcept(cq.query(get_completion_scheduler<completion-tag>)) == true`であること。 |
| 49 | +
|
| 50 | +
|
| 51 | +## 例 |
| 52 | +```cpp |
| 53 | +#include <execution> |
| 54 | +namespace ex = std::execution; |
| 55 | +
|
| 56 | +int main() |
| 57 | +{ |
| 58 | + ex::run_loop loop; |
| 59 | + ex::scheduler auto loop_sch = loop.get_scheduler(); |
| 60 | +
|
| 61 | + // schedule(loop_sch)の完了Schedulerはloop_schに等しい |
| 62 | + ex::sender auto snd0 = ex::schedule(loop_sch); |
| 63 | + auto sch0 = ex::get_completion_scheduler<ex::set_value_t>(ex::get_env(snd0)); |
| 64 | + assert(sch0 == loop_sch); |
| 65 | +
|
| 66 | + // 完了Schedulerは接続されたSenderへと引き継がれる |
| 67 | + ex::sender auto snd1 = snd0 | ex::then([]{ return 42; }); |
| 68 | + auto sch1 = ex::get_completion_scheduler<ex::set_value_t>(ex::get_env(snd1)); |
| 69 | + assert(sch1 == loop_sch); |
| 70 | +
|
| 71 | +#if 0 |
| 72 | + // just Senderは完了Schedulerを持たない |
| 73 | + ex::sender auto snd2 = ex::just(42); |
| 74 | + auto sch2 = ex::get_completion_scheduler<ex::set_value_t>(ex::get_env(snd2)); |
| 75 | +#endif |
| 76 | +} |
| 77 | +``` |
| 78 | +* ex::get_completion_scheduler[color ff0000] |
| 79 | +* ex::run_loop[link run_loop.md.nolink] |
| 80 | +* ex::scheduler[link scheduler.md] |
| 81 | +* ex::sender[link sender.md] |
| 82 | +* ex::schedule[link schedule.md] |
| 83 | +* ex::set_value_t[link set_value.md] |
| 84 | +* ex::get_env[link get_env.md] |
| 85 | +* ex::then[link then.md.nolink] |
| 86 | + |
| 87 | +### 出力 |
| 88 | +``` |
| 89 | +``` |
| 90 | + |
| 91 | + |
| 92 | +## バージョン |
| 93 | +### 言語 |
| 94 | +- C++26 |
| 95 | + |
| 96 | +### 処理系 |
| 97 | +- [Clang](/implementation.md#clang): ?? |
| 98 | +- [GCC](/implementation.md#gcc): ?? |
| 99 | +- [ICC](/implementation.md#icc): ?? |
| 100 | +- [Visual C++](/implementation.md#visual_cpp): ?? |
| 101 | + |
| 102 | + |
| 103 | +## 関連項目 |
| 104 | +- [`execution::scheduler`](scheduler.md) |
| 105 | +- [`execution::schedule`](schedule.md) |
| 106 | +- [`execution::set_value`](set_value.md) |
| 107 | +- [`execution::set_error`](set_error.md) |
| 108 | +- [`execution::set_stopped`](set_stopped.md) |
| 109 | + |
| 110 | + |
| 111 | +## 参照 |
| 112 | +- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html) |
0 commit comments