Standard library header <execution> (C++17)
From cppreference.com
This header is part of the execution and algorithm libraries.
Classes | |
(C++17) |
test whether a class represents an execution policy (class template) |
Defined in namespace
std::execution | |
(C++17)(C++17)(C++17)(C++20) |
execution policy types (class) |
Constants | |
Defined in namespace
std::execution | |
(C++17)(C++17)(C++17)(C++20) |
global execution policy objects (constant) |
Execution control library
Concepts | |
Schedulers | |
Defined in namespace
std::execution | |
(C++26) |
specifies that a type is a scheduler, a handle to an execution resource (concept) |
Senders | |
Defined in namespace
std::execution | |
(C++26) |
specifies that a type is a sender, a description of asynchronous work (concept) |
(C++26) |
specifies that the ways a sender can complete are known, for a given environment or without one (concept) |
(C++26) |
specifies that the ways a sender can complete depend on the environment it is started in (concept) |
Receivers | |
Defined in namespace
std::execution | |
(C++26) |
specifies that a type is a receiver (concept) |
| specifies that a receiver can be recreated from the address of the operation state it was connected to (concept) | |
Operation states | |
Defined in namespace
std::execution | |
(C++26) |
specifies that a type is an operation state (concept) |
Asynchronous scopes | |
Defined in namespace
std::execution | |
(C++26) |
specifies the requirements for an RAII handle that represents an active association with an asynchronous scope (concept) |
(C++26) |
specifies a non-owning handle to an asynchronous scope that behaves like a reference to asynchronous scope (concept) |
Utility components | |
Execution contexts | |
Defined in namespace
std::execution | |
(C++26) |
execution resource holding a thread-safe MPSC task queue and a manually-driven event loop (class) |
Execution domains | |
Defined in namespace
std::execution | |
(C++26) |
execution domain of the standard library's own implementations of the sender algorithms (class) |
| execution domain of work that can complete in one of several domains, using the default implementations of the algorithms (class template) | |
(C++26) |
transforms into a new sender under a given execution domain tag (function template) |
(C++26) |
runs an algorithm that consumes a sender with the implementation of a given execution domain (function template) |
Forward progress guarantee | |
Defined in namespace
std::execution | |
| specifies a forward progress guarantee of execution agents created by the scheduler's associated execution resource (enum) | |
Environments | |
Defined in namespace
std::execution | |
(C++26) |
builds a queryable object from a query object and a value (class template) |
(C++26) |
aggregates several queryable objects into one queryable object (class template) |
(C++26)(C++26) |
returns the associated queryable object for its given argument (customization point object) |
Queries | |
Defined in namespace
std | |
(C++26) |
asks a query object whether it should be forwarded through queryable adaptors (customization point object) |
(C++26) |
asks a queryable object for its associated allocator (customization point object) |
(C++26)(C++26) |
asks a queryable object for the stop token of an asynchronous operation, or obtains the type of that token (customization point object) |
Defined in namespace
std::execution | |
(C++26) |
asks a queryable object for its associated execution domain tag (customization point object) |
| asks the completion domain associated with a completion tag from a sender's attributes (customization point object) | |
(C++26) |
asks a queryable object for its associated scheduler (customization point object) |
| asks a queryable object for the scheduler an operation will be or was started on (customization point object) | |
| asks a queryable object for a scheduler that can be used to delegate work to for the purpose of forward progress delegation (customization point object) | |
| obtains the completion scheduler associated with a completion tag from a sender's attributes (customization point object) | |
| asks a scheduler about its execution::forward_progress_guarantee (customization point object) | |
| asks a queryable object for its associated awaitable completion adaptor (customization point object) | |
Completion signatures | |
Defined in namespace
std::execution | |
| lists the ways a sender can complete (class template) | |
| obtains the completion signatures of a sender, or their type (function) | |
| exception thrown when the completion signatures of a sender are requested without the environment they depend on (class) | |
(C++26) |
obtains the tag type of a sender (alias template) |
(C++26) |
obtains the value completion type of a sender (alias template) |
(C++26) |
obtains the error completion type of a sender (alias template) |
(C++26) |
determines whether the sender supports stopped completion (variable template) |
Coroutine utility | |
Defined in namespace
std::execution | |
(C++26) |
transforms an expression into awaitable object within a particular coroutine (customization point object) |
| when used as the base class of a coroutine promise type, enables senders to be awaitable within that coroutine type (class template) | |
(C++26) |
adapts a sender into one that completes on the scheduler the operation was started on (customization point object) |
(C++26) |
a trivial scheduler that completes immediately and synchronously on the thread that calls std::execution::start on the operation state produced by its sender (class) |
(C++26) |
represents a sender that can be used as the return type of coroutine functions (class template) |
(C++26) |
holds an error that a task coroutine passes to co_yield to complete with that error (class template) |
(C++26) |
provides a uniform, type-erased interface, which allows to store, pass around, and invoke scheduling operations on arbitrary infallible schedulers (class) |
Asynchronous scopes | |
Defined in namespace
std::execution | |
| a lightweight, reference-counted asynchronous scope. It tracks how many dynamically spawned asynchronous operations are currently running (class) | |
(C++26) |
a reference-counted asynchronous scope like simple_counting_scope, which can also request stop for all the asynchronous operations it tracks (class) |
Parallel scheduler | |
Defined in namespace
std::execution | |
| represents a handle of a shared global execution resource (such as a OS-provided system thread pool) optimized for parallel execution (class) | |
obtains a parallel_scheduler for the shared execution resource that runs work in parallel (function) | |
Defined in namespace
| |
interface through which a parallel_scheduler_backend completes an operation and queries its receiver (class) | |
used for bulk_chunked and bulk_unchunked customizations that will also receive notifications from implementations of parallel_scheduler_backend corresponding to different iterations (class) | |
serves as the abstraction bridge between the user-facing parallel_scheduler and the backend execution resource (such as a OS-provided system thread pool) (class) | |
returns the backend object that every parallel_scheduler uses; a program can replace it to provide its own backend (function) | |
Core operations | |
Operation state | |
Defined in namespace
std::execution | |
(C++26) |
connects a sender with a receiver (customization point object) |
(C++26) |
starts the asynchronous operation associated with an operation_state object (customization point object) |
Completion functions | |
Defined in namespace
std::execution | |
(C++26) |
value completion function indicating successful completion (customization point object) |
(C++26) |
error completion function indicating that an error occurred during calculation or scheduling (customization point object) |
(C++26) |
stopped completion function indicating that an operation ended before it could achieve success or failure (customization point object) |
Sender algorithms | |
Sender factories | |
Defined in namespace
std::execution | |
(C++26) |
obtains a sender that completes, with no values, on an execution agent of a given scheduler (customization point object) |
(C++26) |
returns a sender that immediately sends copies of the given values (customization point object) |
(C++26) |
returns a sender that immediately sends a copy of the given error (customization point object) |
(C++26) |
returns a sender that immediately completes with the stopped signal (customization point object) |
(C++26) |
creates a sender that queries its receiver's associated environment (customization point object) |
Pipeable sender adaptors | |
Defined in namespace
std::execution | |
| helper base class template for defining a pipeable sender adaptor closure object (class template) | |
Sender adaptors | |
Defined in namespace
std::execution | |
(C++26) |
adapts a sender so that the operations inside it see extra or different values in their execution environment (customization point object) |
(C++26) |
shields the provided sender from external cancellation requests, ensuring that the critical task runs uninterrupted to completion (customization point object) |
(C++26) |
adapts a provided sender into one that will start an execution on the provided scheduler's execution resource (customization point object) |
(C++26) |
adapts a provided sender into one that completes on the provided scheduler's execution resource (customization point object) |
(C++26) |
a customization hook for how work leaves a scheduler's execution context (completes like the sender it wraps) (customization point object) |
(C++26) |
adapts a sender to run it (or a continuation of it) on the provided scheduler, then return to the scheduler it came from (customization point object) |
(C++26) |
chains a function onto a sender, calling it with the values the sender sends and sending its result on (customization point object) |
(C++26) |
chains a function onto a sender, calling it with the error if the sender fails and sending its result on as a value (customization point object) |
(C++26) |
chains a function onto a sender, calling it if the sender is cancelled and sending its result on as a value (customization point object) |
(C++26) |
chains a function onto a sender, calling it with the values the sender sends and continuing with the sender it returns (customization point object) |
(C++26) |
chains a function onto a sender, calling it with the error if the sender fails and continuing with the sender it returns (customization point object) |
(C++26) |
chains a function onto a sender, calling it if the sender is cancelled and continuing with the sender it returns (customization point object) |
(C++26)(C++26)(C++26) |
runs a function for every index in a range after a sender completes, so the work can be spread over a scheduler's execution resources (customization point object) |
(C++26) |
adapts multiple input senders into a sender that completes once all of the input senders have completed (customization point object) |
| adapts multiple input senders, with each possibly having multiple completion signatures, into a sender that completes once all of the input senders have completed (customization point object) | |
(C++26) |
adapts a sender that can complete with several different sets of values into one that completes with a single std::variant of tuples (customization point object) |
returns a sender that maps the value channel to std::optional<std::decay_t<T>> and the stopped channel to std::nullopt(customization point object) | |
(C++26) |
returns a sender that maps the stopped channel to an error (customization point object) |
(C++26) |
tries to associate a sender with an asynchronous scope such that the scope can track the lifetime of any asynchronous operations created with the sender (customization point object) |
(C++26) |
eagerly starts a sender within an asynchronous scope and returns a sender that completes with its result, or stopped if the scope did not accept it (customization point object) |
Sender consumers | |
Defined in namespace
std::this_thread | |
(C++26) |
blocks current thread until the specified sender completes and returns its async result (customization point object) |
| blocks current thread until the specified sender with possibly multiple completion signatures completes and returns its async result (customization point object) | |
Defined in namespace
std::execution | |
(C++26) |
eagerly launches the given sender within an asynchronous scope, returning immediately without waiting for it to finish (customization point object) |
Synopsis
namespace std {
// execution policy type trait
template<class T>
struct is_execution_policy; // freestanding
template<class T>
constexpr bool is_execution_policy_v = is_execution_policy<T>::value; // freestanding
}
namespace std::execution {
// sequenced execution policy
class sequenced_policy;
// parallel execution policy
class parallel_policy;
// parallel and unsequenced execution policy
class parallel_unsequenced_policy;
// unsequenced execution policy
class unsequenced_policy;
// execution policy objects
inline constexpr sequenced_policy seq{ /* unspecified */ };
inline constexpr parallel_policy par{ /* unspecified */ };
inline constexpr parallel_unsequenced_policy par_unseq{ /* unspecified */ };
inline constexpr unsequenced_policy unseq{ /* unspecified */ };
}
namespace std {
// helper concepts
template<class T>
concept /*movable-value*/ = /* see description */; // exposition only
template<class From, class To>
concept /*decays-to*/ = same_as<decay_t<From>, To>; // exposition only
template<class T>
concept /*class-type*/ = /*decays-to*/<T, T> && is_class_v<T>; // exposition only
// queryable objects
template<class T>
concept /*queryable*/ = /* see description */; // exposition only
// queries
struct forwarding_query_t
{ /* unspecified */
};
struct get_allocator_t
{ /* unspecified */
};
struct get_stop_token_t
{ /* unspecified */
};
inline constexpr forwarding_query_t forwarding_query{};
inline constexpr get_allocator_t get_allocator{};
inline constexpr get_stop_token_t get_stop_token{};
template<class T>
using stop_token_of_t = remove_cvref_t<decltype(get_stop_token(declval<T>()))>;
template<class T>
concept /*forwarding-query*/ = forwarding_query(T{}); // exposition only
}
namespace std::execution {
// queries
struct get_domain_t
{ /* unspecified */
};
struct get_scheduler_t
{ /* unspecified */
};
struct get_start_scheduler_t
{ /* unspecified */
};
struct get_delegation_scheduler_t
{ /* unspecified */
};
struct get_forward_progress_guarantee_t
{ /* unspecified */
};
template<class CPO>
struct get_completion_scheduler_t
{ /* unspecified */
};
template<class CPO = void>
struct get_completion_domain_t
{ /* unspecified */
};
struct get_await_completion_adaptor_t
{ /* unspecified */
};
inline constexpr get_domain_t get_domain{};
inline constexpr get_scheduler_t get_scheduler{};
inline constexpr get_start_scheduler_t get_start_scheduler{};
inline constexpr get_delegation_scheduler_t get_delegation_scheduler{};
enum class forward_progress_guarantee;
inline constexpr get_forward_progress_guarantee_t get_forward_progress_guarantee{};
template<class CPO>
constexpr get_completion_scheduler_t<CPO> get_completion_scheduler{};
template<class CPO = void>
constexpr get_completion_domain_t<CPO> get_completion_domain{};
inline constexpr get_await_completion_adaptor_t get_await_completion_adaptor{};
struct get_env_t
{ /* unspecified */
};
inline constexpr get_env_t get_env{};
template<class T>
using env_of_t = decltype(get_env(declval<T>()));
// execution domains
template<class... Domains>
struct indeterminate_domain;
// execution domains
struct default_domain;
// schedulers
struct scheduler_tag
{};
template<class Sch>
concept scheduler = /* see description */;
// receivers
struct receiver_tag
{};
template<class Rcvr>
concept receiver = /* see description */;
template<class Rcvr, class Completions>
concept /*receiver-of*/ = /* see description */; // exposition only
template<class Rcvr, class ChildOp>
concept inlinable_receiver = /* see description */;
struct set_value_t
{ /* unspecified */
};
struct set_error_t
{ /* unspecified */
};
struct set_stopped_t
{ /* unspecified */
};
inline constexpr set_value_t set_value{};
inline constexpr set_error_t set_error{};
inline constexpr set_stopped_t set_stopped{};
// operation states
struct operation_state_tag
{};
template<class O>
concept operation_state = /* see description */;
struct start_t;
inline constexpr start_t start{};
// senders
struct sender_tag
{};
template<class Sndr>
inline constexpr bool enable_sender = /* see description */;
template<class Sndr>
concept sender = /* see description */;
template<class Sndr, class... Env>
concept sender_in = /* see description */;
template<class Sndr>
concept dependent_sender = /* see description */;
template<class Sndr, class Rcvr>
concept /*sender-to*/ = /* see description */; // exposition only
template<class... Ts>
struct /*type-list*/; // exposition only
template<class... Ts>
using /*decayed-tuple*/ = tuple<decay_t<Ts>...>; // exposition only
template<class... Ts>
using /*variant-or-empty*/ = /* see description */; // exposition only
template<class Sndr, class Env = env<>,
template<class...> class Tuple = /*decayed-tuple*/,
template<class...> class Variant = /*variant-or-empty*/>
requires sender_in<Sndr, Env>
using value_types_of_t = /* see description */;
template<class Sndr, class Env = env<>,
template<class...> class Variant = /*variant-or-empty*/>
requires sender_in<Sndr, Env>
using error_types_of_t = /* see description */;
template<class Sndr, class Env = env<>>
requires sender_in<Sndr, Env>
constexpr bool sends_stopped = /* see description */;
template<class Sndr, class... Env>
using /*single-sender-value-type*/ = /* see description */; // exposition only
template<class Sndr, class... Env>
concept /*single-sender*/ = /* see description */; // exposition only
template<sender Sndr>
using tag_of_t = /* see description */;
// sender transformations
template<sender Sndr, /*queryable*/ Env>
constexpr decltype(auto) transform_sender(Sndr&& sndr,
const Env& env) noexcept(/* see description */);
// sender algorithm application
template<class Domain, class Tag, sender Sndr, class... Args>
constexpr decltype(auto) apply_sender(
Domain dom, Tag, Sndr&& sndr, Args&&... args) noexcept(/* see description */);
// get completion signatures
template<class Sndr, class... Env>
consteval auto get_completion_signatures() -> /*valid-completion-signatures*/ auto;
template<class Sndr, class... Env>
requires sender_in<Sndr, Env...>
using completion_signatures_of_t = decltype(get_completion_signatures<Sndr, Env...>());
// the connect sender algorithm
struct connect_t;
inline constexpr connect_t connect{};
template<class Sndr, class Rcvr>
using connect_result_t =
decltype(connect(declval<Sndr>(), declval<Rcvr>()));
// sender factories
struct just_t
{ /* unspecified */
};
struct just_error_t
{ /* unspecified */
};
struct just_stopped_t
{ /* unspecified */
};
struct schedule_t
{ /* unspecified */
};
inline constexpr just_t just{};
inline constexpr just_error_t just_error{};
inline constexpr just_stopped_t just_stopped{};
inline constexpr schedule_t schedule{};
inline constexpr /* unspecified */ read_env{};
template<scheduler Sch>
using schedule_result_t = decltype(schedule(declval<Sch>()));
// sender adaptors
template</*class-type*/ D>
struct sender_adaptor_closure
{};
struct starts_on_t
{ /* unspecified */
};
struct continues_on_t
{ /* unspecified */
};
struct on_t
{ /* unspecified */
};
struct schedule_from_t
{ /* unspecified */
};
struct then_t
{ /* unspecified */
};
struct upon_error_t
{ /* unspecified */
};
struct upon_stopped_t
{ /* unspecified */
};
struct let_value_t
{ /* unspecified */
};
struct let_error_t
{ /* unspecified */
};
struct let_stopped_t
{ /* unspecified */
};
struct bulk_t
{ /* unspecified */
};
struct bulk_chunked_t
{ /* unspecified */
};
struct bulk_unchunked_t
{ /* unspecified */
};
struct when_all_t
{ /* unspecified */
};
struct when_all_with_variant_t
{ /* unspecified */
};
struct into_variant_t
{ /* unspecified */
};
struct stopped_as_optional_t
{ /* unspecified */
};
struct stopped_as_error_t
{ /* unspecified */
};
struct associate_t
{ /* unspecified */
};
struct spawn_future_t
{ /* unspecified */
};
inline constexpr /* unspecified */ write_env{};
inline constexpr /* unspecified */ unstoppable{};
inline constexpr starts_on_t starts_on{};
inline constexpr continues_on_t continues_on{};
inline constexpr on_t on{};
inline constexpr schedule_from_t schedule_from{};
inline constexpr then_t then{};
inline constexpr upon_error_t upon_error{};
inline constexpr upon_stopped_t upon_stopped{};
inline constexpr let_value_t let_value{};
inline constexpr let_error_t let_error{};
inline constexpr let_stopped_t let_stopped{};
inline constexpr bulk_t bulk{};
inline constexpr bulk_chunked_t bulk_chunked{};
inline constexpr bulk_unchunked_t bulk_unchunked{};
inline constexpr when_all_t when_all{};
inline constexpr when_all_with_variant_t when_all_with_variant{};
inline constexpr into_variant_t into_variant{};
inline constexpr stopped_as_optional_t stopped_as_optional{};
inline constexpr stopped_as_error_t stopped_as_error{};
inline constexpr associate_t associate{};
inline constexpr spawn_future_t spawn_future{};
}
namespace std::this_thread {
// consumers
struct sync_wait_t
{ /* unspecified */
};
struct sync_wait_with_variant_t
{ /* unspecified */
};
inline constexpr sync_wait_t sync_wait{};
inline constexpr sync_wait_with_variant_t sync_wait_with_variant{};
}
namespace std::execution {
// consumers
struct spawn_t
{ /* unspecified */
};
inline constexpr spawn_t spawn{};
// completion signatures
template<class Fn>
concept /*completion-signature*/ = /* see description */; // exposition only
template</*completion-signature*/... Fns>
struct completion_signatures;
template<class Sigs>
concept /*valid-completion-signatures*/ = /* see description */; // exposition only
struct dependent_sender_error : exception {};
// class template prop
template<class QueryTag, class ValueType>
struct prop;
// class template env
template</*queryable*/... Envs>
struct env;
// run_loop
class run_loop;
// coroutine utility as_awaitable
struct as_awaitable_t
{ /* unspecified */
};
inline constexpr as_awaitable_t as_awaitable{};
// coroutine utility with_awaitable_senders
template</*class-type*/ Promise>
struct with_awaitable_senders;
// coroutine utility affine
struct affine_t
{ /* unspecified */
};
inline constexpr affine_t affine{};
// inline scheduler
class inline_scheduler;
// task scheduler
class task_scheduler;
template<class E>
struct with_error
{
using type = remove_cvref_t<E>;
type error;
};
template<class E>
with_error(E) -> with_error<E>;
// class template task
template<class T, class Environment>
class task;
// scope concepts
template<class Token>
concept scope_association = /* see description */;
template<class Token>
concept scope_token = /* see description */;
// simple counting scope
class simple_counting_scope;
// counting scope
class counting_scope;
// parallel scheduler
class parallel_scheduler;
parallel_scheduler get_parallel_scheduler();
// namespace parallel_scheduler_replacement
namespace parallel_scheduler_replacement {
struct receiver_proxy;
struct bulk_item_receiver_proxy;
struct parallel_scheduler_backend;
shared_ptr<parallel_scheduler_backend> query_parallel_scheduler_backend();
}
}
Helper concepts
namespace std {
template<class T>
concept /*movable-value*/ = // exposition only
move_constructible<decay_t<T>> && constructible_from<decay_t<T>, T> &&
(!is_array_v<remove_reference_t<T>>);
}
namespace std {
template<class T>
concept /*queryable*/ = destructible<T>; // exposition only
}
namespace std::execution {
template<class Sndr, class... Env>
concept /*single-sender*/ = sender_in<Sndr, Env...> && requires {
typename /*single-sender-value-type*/<Sndr, Env...>;
};
}
Helper classes
namespace std::execution {
struct /*empty-variant*/
{ // exposition only
/*empty-variant*/() = delete;
};
}
enum std::execution::forward_progress_guarantee
namespace std::execution {
enum class forward_progress_guarantee
{
concurrent,
parallel,
weakly_parallel
};
}
Concept scheduler
namespace std::execution {
template<class Sch>
concept scheduler =
derived_from<typename remove_cvref_t<Sch>::scheduler_concept, scheduler_tag> &&
/*queryable*/<Sch> &&
requires(Sch&& sch) {
{
schedule(std::forward<Sch>(sch))
} -> sender;
{
get_forward_progress_guarantee(sch)
} -> same_as<forward_progress_guarantee>;
} && equality_comparable<remove_cvref_t<Sch>> &&
copyable<remove_cvref_t<Sch>>;
}
Concept receiver
namespace std::execution {
template<class Rcvr>
concept receiver =
derived_from<typename remove_cvref_t<Rcvr>::receiver_concept, receiver_tag> &&
requires(const remove_cvref_t<Rcvr>& rcvr) {
{
get_env(rcvr)
} -> /*queryable*/;
} && move_constructible<remove_cvref_t<Rcvr>> && // rvalues are movable, and
constructible_from<remove_cvref_t<Rcvr>, Rcvr> && // lvalues are copyable, and
is_nothrow_move_constructible_v<remove_cvref_t<Rcvr>>; // no-throw-movable
template<class Signature, class Rcvr>
concept /*valid-completion-for*/ = requires(Signature* sig) { // exposition only
[]<class Tag, class... Args>(Tag(*)(Args...))
requires /*callable*/<Tag, remove_cvref_t<Rcvr>, Args...>
{
}
(sig);
};
template<class Rcvr, class Completions>
concept /*has-completions*/ = requires(Completions* completions) { // exposition only
[]</*valid-completion-for*/<Rcvr>... Sigs>(completion_signatures<Sigs...>*) {
}(completions);
};
template<class Rcvr, class Completions>
concept /*receiver-of*/ = // exposition only
receiver<Rcvr> && /*has-completions*/<Rcvr, Completions>;
}
Concept operation_state
namespace std::execution {
template<class O>
concept operation_state =
derived_from<typename O::operation_state_concept, operation_state_tag> &&
requires(O& o) {
start(o);
};
}