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
処理系
- Clang: ??
- GCC: ??
- ICC: ??
- Visual C++: ??