|
| 1 | +# operation_state |
| 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 O> |
| 10 | + concept operation_state = |
| 11 | + derived_from<typename O::operation_state_concept, operation_state_t> && |
| 12 | + is_object_v<O> && |
| 13 | + requires (O& o) { |
| 14 | + { start(o) } noexcept; |
| 15 | + }; |
| 16 | + |
| 17 | + struct operation_state_t {}; // タグ型 |
| 18 | +} |
| 19 | +``` |
| 20 | +* derived_from[link /reference/concepts/derived_from.md] |
| 21 | +* is_object_v[link /reference/type_traits/is_object.md] |
| 22 | +* start[link start.md.nolink] |
| 23 | +
|
| 24 | +## 概要 |
| 25 | +`operation_state`は、型`O`がOperation State型の要件を満たすことを表すコンセプトである。 |
| 26 | +
|
| 27 | +下記をみたすクラス型はOperation Stateとみなせる。 |
| 28 | +
|
| 29 | +- `operation_state_t`をメンバ型`O::operation_state_concept`として定義するクラス型 |
| 30 | +- `O`型の左辺値`o`に対して`execution::start(o)`が有効な式かつ例外送出されないこと |
| 31 | +
|
| 32 | +非同期操作の生存期間中に`operation_state`オブジェクトが破棄されると、未定義の動作を引き起こす。 |
| 33 | +
|
| 34 | +
|
| 35 | +## 例 |
| 36 | +```cpp |
| 37 | +#include <print> |
| 38 | +#include <execution> |
| 39 | +namespace ex = std::execution; |
| 40 | +
|
| 41 | +struct ValueReceiver { |
| 42 | + using receiver_concept = ex::receiver_t; |
| 43 | +
|
| 44 | + void set_value(int v) noexcept |
| 45 | + { |
| 46 | + std::println("{}", v); |
| 47 | + } |
| 48 | +}; |
| 49 | +
|
| 50 | +int main() |
| 51 | +{ |
| 52 | + // 値42を送信するSender |
| 53 | + ex::sender auto sndr = ex::just(42); |
| 54 | + // int値を受信して表示するReceiver |
| 55 | + ValueReceiver rcvr; |
| 56 | + |
| 57 | + // SenderとReceiverを接続 |
| 58 | + ex::operation_state auto op = ex::connect(sndr, rcvr); |
| 59 | + // Operation Stateを開始 |
| 60 | + ex::start(op); |
| 61 | +} |
| 62 | +``` |
| 63 | +* ex::operation_state[color ff0000] |
| 64 | +* ex::sender[link sender.md] |
| 65 | +* ex::just[link just.md.nolink] |
| 66 | +* ex::connect[link connect.md.nolink] |
| 67 | +* ex::start[link start.md.nolink] |
| 68 | + |
| 69 | +### 出力 |
| 70 | +``` |
| 71 | +42 |
| 72 | +``` |
| 73 | + |
| 74 | + |
| 75 | +## バージョン |
| 76 | +### 言語 |
| 77 | +- C++26 |
| 78 | + |
| 79 | +### 処理系 |
| 80 | +- [Clang](/implementation.md#clang): ?? |
| 81 | +- [GCC](/implementation.md#gcc): ?? |
| 82 | +- [ICC](/implementation.md#icc): ?? |
| 83 | +- [Visual C++](/implementation.md#visual_cpp): ?? |
| 84 | + |
| 85 | + |
| 86 | +## 関連項目 |
| 87 | +- [`execution::connect`](connect.md.nolink) |
| 88 | + |
| 89 | + |
| 90 | +## 参照 |
| 91 | +- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html) |
0 commit comments