最終更新日時(UTC):
が更新

履歴 編集

function template
<execution>

std::execution::env::query(C++26)

template<class QueryTag>
constexpr decltype(auto) query(QueryTag q) const noexcept(see below);

概要

クエリオブジェクトqをキーとして、対応する値を問い合わせる。

テンプレートパラメータ制約

説明専用のコンセプトhas-queryを次のように定義したとき、(has-query<Envs, QueryTag> || ...)trueであること。

template<class Env, class QueryTag>
concept has-query =
  requires (const Env& env) {
    env.query(QueryTag());
  };

効果

説明用のfeを、envクラステンプレートの説明専用メンバ変数envs0_, ..., envsN_のうち最初に式fe.query(q)適格となる要素としたとき、下記と等価。

return fe.query(q);

例外

noexcept(fe.query(q))trueのとき、例外送出しない。 それ以外の場合、式fe.query(q)から送出される例外

#include <concepts>
#include <stop_token>
#include <execution>
using ex = std::execution;

int main()
{
  // get_allocatorとget_stop_tokenをサポートするクエリ可能オブジェクト
  auto env0 = ex::env{
    ex::prop(std::get_allocator, std::allocator<std::byte>{}),
    ex::prop(std::get_stop_token, std::never_stop_token{})
  };
  auto token0 = env0.query(std::get_stop_token);
  static_assert(std::same_as<decltype(token0), std::never_stop_token>);

  // env0のget_stop_tokenクエリオブジェクト動作を上書き
  auto env1 = ex::env{
    ex::prop(std::get_stop_token, std::stop_token{}),
    env0
  };
  auto token1 = env1.query(std::get_stop_token);
  static_assert(std::same_as<decltype(token1), std::stop_token>);
}

出力

バージョン

言語

  • C++26

処理系

参照