|
| 1 | +# get_stop_token |
| 2 | +* execution[meta header] |
| 3 | +* cpo[meta id-type] |
| 4 | +* std[meta namespace] |
| 5 | +* cpp26[meta cpp] |
| 6 | + |
| 7 | +```cpp |
| 8 | +namespace std { |
| 9 | + struct get_stop_token_t { unspecified }; |
| 10 | + constexpr get_stop_token_t get_stop_token{}; |
| 11 | +} |
| 12 | +``` |
| 13 | +* unspecified[italic] |
| 14 | +
|
| 15 | +## 概要 |
| 16 | +`get_stop_token`は、[クエリ可能オブジェクト](queryable.md)から[停止トークン](/reference/stop_token/stoppable_token.md)を取得する[クエリオブジェクト](queryable.md)である。 |
| 17 | +
|
| 18 | +コア定数式[`forwarding_query`](forwarding_query.md.nolink)`(get_stop_token)`は`true`値を返す。 |
| 19 | +
|
| 20 | +
|
| 21 | +## 効果 |
| 22 | +式`get_stop_token(env)`は下記と等価であり、[`stoppable_token`](/reference/stop_token/stoppable_token.md)を満たす型の値となる。 |
| 23 | +
|
| 24 | +- 引数`env`がconst修飾された`cenv`を用いて、式`cenv.query(get_stop_token)`が有効であればその値。 |
| 25 | +- そうでなければ、[`never_stop_token{}`](/reference/stop_token/never_stop_token.md) |
| 26 | +
|
| 27 | +
|
| 28 | +## 例外 |
| 29 | +投げない |
| 30 | +
|
| 31 | +
|
| 32 | +## カスタマイゼーションポイント |
| 33 | +const修飾[クエリ可能オブジェクト](queryable.md)`env`に対して式`env.query(get_stop_token)`が呼び出される。 |
| 34 | +このとき、`noexcept(cenv.query(get_stop_token)) == true`であること。 |
| 35 | +
|
| 36 | +
|
| 37 | +## 例 |
| 38 | +```cpp |
| 39 | +#include <concepts> |
| 40 | +#include <stop_token> |
| 41 | +#include <execution> |
| 42 | +namespace ex = std::execution; |
| 43 | +
|
| 44 | +int main() |
| 45 | +{ |
| 46 | + // just Senderは停止トークンを持たない |
| 47 | + ex::sender auto sndr = ex::just(42); |
| 48 | + auto token = std::get_stop_token(ex::get_env(sndr)); |
| 49 | + static_assert(std::same_as<decltype(token), std::never_stop_token>); |
| 50 | +} |
| 51 | +``` |
| 52 | +* std::get_stop_token[color ff0000] |
| 53 | +* ex::sender[link execution/sender.md] |
| 54 | +* ex::just[link execution/just.md.nolink] |
| 55 | +* ex::get_env[link execution/get_env.md] |
| 56 | +* std::never_stop_token[link /reference/stop_token/never_stop_token.md] |
| 57 | + |
| 58 | +### 出力 |
| 59 | +``` |
| 60 | +``` |
| 61 | + |
| 62 | + |
| 63 | +## バージョン |
| 64 | +### 言語 |
| 65 | +- C++26 |
| 66 | + |
| 67 | +### 処理系 |
| 68 | +- [Clang](/implementation.md#clang): ?? |
| 69 | +- [GCC](/implementation.md#gcc): ?? |
| 70 | +- [ICC](/implementation.md#icc): ?? |
| 71 | +- [Visual C++](/implementation.md#visual_cpp): ?? |
| 72 | + |
| 73 | + |
| 74 | +## 関連項目 |
| 75 | +- [`stoppable_token`](/reference/stop_token/stoppable_token.md) |
| 76 | + |
| 77 | + |
| 78 | +## 参照 |
| 79 | +- [P2300R10 `std::execution`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html) |
0 commit comments