Namespaces
Variants

std::execution::sender_in

From cppreference.com
 
 
Execution control library
Concepts
 
Defined in header <execution>
template< class Sndr, class... Env >
concept sender_in =
    execution::sender<Sndr> &&
    (sizeof...(Env) <= 1) &&
    (/*queryable*/<Env> && ...) &&
    /*is-constant*/<execution::get_completion_signatures<Sndr, Env...>()>;
(since C++26)

The concept sender_in specifies that the completion signatures of a sender type Sndr, the list of the ways it can complete, are known:

  • sender_in<Sndr, Env> is satisfied if they are known for a receiver whose environment has type Env;
  • sender_in<Sndr> is satisfied if they are known without an environment, that is, if they are the same wherever the sender is started. Such a sender is called a non-dependent sender.

Sndr includes the value category with which the sender is going to be used: Sndr& for an lvalue, Sndr or Sndr&& for an rvalue. /*queryable*/ is satisfied by any destructible type. /*is-constant*/<v> is satisfied if v is a constant expression: the completion signatures are known if execution::get_completion_signatures<Sndr, Env...>() can be evaluated at compile time without throwing an exception. It throws if

  • there is no Env and the completions of the sender depend on the environment, as for read_env(get_stop_token), which sends the stop token of the receiver's environment. Such a sender satisfies dependent_sender;
  • the sender cannot be used with Env, for example because a function passed to then cannot be called with the values that the previous sender sends in that environment.

Semantic requirements

Sndr and Env model sender_in only if every completion that the sender performs, when it is connected to a receiver whose environment has type Env and started, is one of those listed in execution::completion_signatures_of_t<Sndr, Env>.

Notes

  • sender_in is the requirement of completion_signatures_of_t, value_types_of_t, error_types_of_t, and sends_stopped, and of functions that need to know how a sender completes, such as this_thread::sync_wait.
  • The standard sender algorithms check the senders they are given when they are given a non-dependent sender, so that mistakes are diagnosed where the chain of work is built. Mistakes in a chain that starts with a dependent sender are diagnosed when it is connected to a receiver.
  • If the completion signatures are known both without an environment and with one, those for the environment are a subset of the others, with fewer error or stopped completions. For example, a sender that completes with set_stopped() only when stop is requested does not do so in an environment whose stop token cannot request stop.
  • Earlier drafts also had the concept sender_to, satisfied if a sender could be connected to a given receiver type. It is not part of C++26.

Example

Shows which senders satisfy sender_in without an environment and with one.
The execution control library components may not be available in the online compilers yet, so this link runs the example on Compiler Explorer with stdexec (one of the reference implementations).

#include <concepts>
#include <execution>
#include <stop_token>
#include <string>

namespace ex = std::execution;

// The environment of a receiver that provides a stop token
using stop_env =
    ex::env<ex::prop<std::get_stop_token_t, std::inplace_stop_token>>;

// just(42) completes with set_value(42) wherever it is started
using just_42 = decltype(ex::just(42));
static_assert(ex::sender_in<just_42>);
static_assert(ex::sender_in<just_42, stop_env>);
static_assert(std::same_as<ex::completion_signatures_of_t<just_42>,
                           ex::completion_signatures<ex::set_value_t(int)>>);

// This sender sends the stop token of the receiver's environment, so its
// completions are not known until the environment is
using read_token = decltype(ex::read_env(std::get_stop_token));
static_assert(!ex::sender_in<read_token>);
static_assert(ex::dependent_sender<read_token>);
static_assert(ex::sender_in<read_token, stop_env>);

// A mistake that can only be found when the environment is known:
// the function cannot be called with a stop token
auto takes_string = [](std::string) {};
using bad = decltype(ex::read_env(std::get_stop_token)
                     | ex::then(takes_string));
static_assert(ex::sender<bad>);
static_assert(!ex::sender_in<bad, stop_env>);

int main() {}

See also

specifies that a type is a sender, a description of asynchronous work
(concept) [edit]
specifies that the ways a sender can complete depend on the environment it is started in
(concept) [edit]
obtains the completion signatures of a sender, or their type
(function) [edit]
lists the ways a sender can complete
(class template) [edit]