Files
cppdraft_translate/cppdraft/exec/env.md
2025-10-25 03:02:53 +03:00

3.8 KiB
Raw Blame History

[exec.env]

33 Execution control library [exec]

33.11 Queryable utilities [exec.envs]

33.11.2 Class template env [exec.env]

namespace std::execution {template<queryable... Envs>struct env { Envs0 envs0; // exposition only Envs1 envs1; // exposition only ⋮ Envsn−1 envsn−1; // exposition onlytemplateconstexpr decltype(auto) query(QueryTag q) const noexcept(see below); }; template<class... Envs> env(Envs...) -> env<unwrap_reference_t...>;}

1

#

The class template env is used to construct a queryable object from several queryable objects.

Query invocations on the resulting object are resolved by attempting to query each subobject in lexical order.

2

#

Specializations of env are not assignable.

3

#

It is unspecified whether env supports initialization using a parenthesized expression-list ([dcl.init]), unless the expression-list consist of a single element of type (possibly const) env.

4

#

[Example 1: template<sender Sndr> sender auto parameterize_work(Sndr sndr) {// Make an environment such that:// get_allocator(env) returns a reference to a copy of my_alloc{}// get_scheduler(env) returns a reference to a copy of my_sched{}auto e = env{prop(get_allocator, my_alloc{}), prop(get_scheduler, my_sched{})}; // Parameterize the input sender so that it will use our custom execution environment.return write_env(sndr, e);} — end example]

🔗

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

5

#

Let has-query be the following exposition-only concept:template<class Env, class QueryTag>concept has-query = // exposition onlyrequires (const Env& env) { env.query(QueryTag()); };

6

#

Let fe be the first element ofenvs0, envs1, …, envsn−1 such that the expression fe.query(q) is well-formed.

7

#

Constraints: (has-query<Envs, QueryTag> || ...) is true.

8

#

Effects: Equivalent to: return fe.query(q);

9

#

Remarks: The expression in the noexcept clause is equivalent to noexcept(fe.query(q)).