Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/algorithms/retry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ struct _retry_sender
using _value = stdexec::completion_signatures<stdexec::set_value_t(Ts...)>;

template <class Self, class... Env>
static consteval auto get_completion_signatures() -> stdexec::transform_completion_signatures<
static consteval auto get_completion_signatures() -> stdexec::__transform_completion_signatures_t<
stdexec::completion_signatures_of_t<S&, Env...>,
stdexec::completion_signatures<stdexec::set_error_t(std::exception_ptr)>,
_value,
Expand Down
2 changes: 1 addition & 1 deletion examples/algorithms/then.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ struct _then_sender
stdexec::completion_signatures<stdexec::set_value_t(std::invoke_result_t<F, Args...>)>;

template <class... Env>
using _completions_t = stdexec::transform_completion_signatures<
using _completions_t = stdexec::__transform_completion_signatures_t<
stdexec::completion_signatures_of_t<S, Env...>,
stdexec::completion_signatures<stdexec::set_error_t(std::exception_ptr)>,
_set_value_t>;
Expand Down
6 changes: 3 additions & 3 deletions include/exec/asio/use_sender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ namespace experimental::execution::asio

template <typename Signatures>
using completion_signatures =
::STDEXEC::transform_completion_signatures<Signatures,
::STDEXEC::completion_signatures<>,
transform_set_value_t>;
::STDEXEC::__transform_completion_signatures_t<Signatures,
::STDEXEC::completion_signatures<>,
transform_set_value_t>;

template <typename Sender>
struct sender
Expand Down
2 changes: 1 addition & 1 deletion include/exec/async_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ namespace experimental::execution
using __decay_error_t = completion_signatures<set_error_t(__decay_t<_Ty>)>;

template <class _Sender, class _Env>
using __future_completions_t = transform_completion_signatures_of<
using __future_completions_t = __transform_completion_signatures_of_t<
_Sender,
__env_t<_Env>,
completion_signatures<set_stopped_t(), set_error_t(std::exception_ptr)>,
Expand Down
159 changes: 133 additions & 26 deletions include/exec/completion_signatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,25 @@ namespace experimental::execution
//! by combining explicitly provided signature types with those deduced from pointer
//! arguments.
//!
//! @tparam ExplicitSigs Explicitly specified completion signature types.
//! @tparam DeducedSigs Completion signature types to be deduced from the function arguments.
//! @param unnamed Pointer arguments (unused) used for type deduction of DeducedSigs.
//! \tparam ExplicitSigs Explicitly specified completion signature types. Must be a pack
//! of function types, the returns types of which must be one of
//! \c set_value_t, \c set_error_t, or \c set_stopped_t.
//! \tparam DeducedSigs Completion signature types to be deduced from the function
//! arguments.
//! \param unnamed Pointer arguments (unused) for type deduction of
//! \c DeducedSigs. Must be a pack of function pointer types, the
//! returns types of which must be one of \c set_value_t,
//! \c set_error_t, or \c set_stopped_t.
//!
//! @return An instance of `STDEXEC::completion_signatures` containing the combined
//! \return An instance of \c STDEXEC::completion_signatures containing the combined
//! signatures.
//!
//! @note This is a `consteval` function, meaning it is only callable in constant evaluation
//! contexts (compile-time). It always returns a default-constructed instance of the result
//! type.
//! \note This is a \c consteval function, meaning it is only callable in constant
//! evaluation contexts (compile-time). It always returns a default-constructed
//! instance of the result type.
//!
//! @note The function uses pointer arguments for type deduction without requiring actual object
//! instances.
//! \note The function uses pointer arguments for type deduction without requiring
//! actual object instances.
template <class... ExplicitSigs, class... DeducedSigs>
[[nodiscard]]
consteval auto make_completion_signatures(DeducedSigs*...) noexcept
Expand All @@ -95,33 +101,134 @@ namespace experimental::execution

//////////////////////////////////////////////////////////////////////////////////////////////////
// transform_completion_signatures

template <class _SetTag>
using keep_completion = STDEXEC::__keep_completion<_SetTag>;

using ignore_completion = STDEXEC::__ignore_completion;

template <class _SetTag, class _Fn, class... _AlgoTag>
using transform_arguments = STDEXEC::__transform_arguments<_SetTag, _Fn, _AlgoTag...>;
template <class _SetTag, template <class> class _Fn, class... _AlgoTag>
using transform_arguments =
STDEXEC::__transform_arguments<_SetTag, STDEXEC::__q1<_Fn>, _AlgoTag...>;

template <class _SetTag, class... _AlgoTag>
using decay_arguments = STDEXEC::__decay_arguments<_SetTag, _AlgoTag...>;

template <class _Completions,
class _ValueFn = keep_completion<STDEXEC::set_value_t>,
class _ErrorFn = keep_completion<STDEXEC::set_error_t>,
class _StoppedFn = keep_completion<STDEXEC::set_stopped_t>,
class _ExtraSigs = STDEXEC::completion_signatures<>>
consteval auto transform_completion_signatures(_Completions,
_ValueFn __value_fn = {},
_ErrorFn __error_fn = {},
_StoppedFn __stopped_fn = {},
_ExtraSigs = {})
//! \brief Transforms completion signatures using provided transformation functions.
//!
//! This consteval function transforms a set of completion signatures by applying
//! custom transformation functions to value, error, and stopped completion cases.
//! The result can be augmented with additional extra signatures.
//!
//! \tparam Completions The input completion signatures to transform. Must be a
//! specialization of \c STDEXEC::completion_signatures.
//! \tparam ValueFn Function object that transforms set_value_t completions.
//! Defaults to keep_completion<set_value_t>.
//! \tparam ErrorFn Function object that transforms set_error_t completions.
//! Defaults to keep_completion<set_error_t>.
//! \tparam StoppedFn Function object that transforms set_stopped_t completions.
//! Defaults to keep_completion<set_stopped_t>.
//! \tparam ExtraSigs Additional completion signatures to append to the result.
//! Must be a specialization of \c STDEXEC::completion_signatures.
//! Defaults to \c STDEXEC::completion_signatures().
//!
//! \param completions The input completion signatures object.
//! \param value_fn Value transformation function instance.
//! \param error_fn Error transformation function instance.
//! \param stopped_fn Stopped transformation function instance.
//! \param extra_sigs Extra signatures to append to the result.
//!
//! \return A transformed completion_signatures object combining the transformed
//! input signatures with the extra signatures.
//!
//! \par Example
//!
//! The following example demonstrates how to use \c transform_completion_signatures
//! to compute the completion signatures of the \c then sender.
//!
//! \code{.cpp}
//! namespace ex = STDEXEC;
//!
//! // A helper function to transform the value types of the child sender into the value
//! // types of the then sender.
//! template <class Fn, class... Args>
//! consteval auto _transform_values()
//! {
//! if constexpr (!std::invocable<Fn, Args...>)
//! {
//! // If Fn cannot be invoked with the given arguments, produce a compile-time
//! // error.
//! return exec::throw_compile_time_error<
//! WHAT(FUNCTION_IS_NOT_CALLABLE_WITH_THE_GIVEN_ARGUMENTS),
//! WHERE(IN_ALGORITHM, then_t),
//! WITH_FUNCTION(Fn),
//! WITH_ARGUMENTS(Args...)>();
//! }
//! else
//! {
//! // transform the value types of the child sender into the value types of the
//! // then sender by applying Fn to them.
//! using result_t = std::invoke_result_t<Fn, Args...>;
//! constexpr bool is_void = std::is_void_v<result_t>;
//! constexpr bool nothrow = std::is_nothrow_invocable_v<Fn, Args...>;
//! if constexpr (is_void && nothrow)
//! {
//! return ex::completion_signatures<set_value_t()>();
//! }
//! else if constexpr (is_void && !nothrow)
//! {
//! return ex::completion_signatures<set_value_t(),
//! set_error_t(std::exception_ptr)>();
//! }
//! else if constexpr (!is_void && nothrow)
//! {
//! return ex::completion_signatures<set_value_t(result_t)>();
//! }
//! else /* !is_void && !nothrow */
//! {
//! return ex::completion_signatures<set_value_t(result_t),
//! set_error_t(std::exception_ptr)>();
//! }
//! }
//! }
//!
//! template <class Child, class Fn>
//! struct then_sender
//! {
//! using sender_concept = ex::sender_t;
//!
//! template <class Self, class... Env>
//! static consteval auto get_completion_signatures()
//! {
//! // Compute the completion signatures of the child sender, and then transform
//! // them into the completion signatures of the `then` sender.
//! auto child_completions = exec::get_child_completion_signatures<Self, Child, Env...>();
//! auto value_fn = []<class... Args>() { return _transform_values<Fn, Args...>(); };
//!
//! return exec::transform_completion_signatures(child_completions, value_fn);
//! }
//!
//! // ...
//! };
//! \endcode
//!
//! \note This function is evaluated at compile-time (consteval).
template <class Completions,
class ValueFn = keep_completion<STDEXEC::set_value_t>,
class ErrorFn = keep_completion<STDEXEC::set_error_t>,
class StoppedFn = keep_completion<STDEXEC::set_stopped_t>,
class ExtraSigs = STDEXEC::completion_signatures<>>
consteval auto transform_completion_signatures(Completions,
ValueFn value_fn = {},
ErrorFn error_fn = {},
StoppedFn stopped_fn = {},
ExtraSigs = {})
{
return STDEXEC::__transform_completion_signatures(_Completions{},
__value_fn,
__error_fn,
__stopped_fn,
_ExtraSigs{});
return STDEXEC::__transform_completion_signatures(Completions{},
value_fn,
error_fn,
stopped_fn,
ExtraSigs{});
}
} // namespace experimental::execution

Expand Down
20 changes: 10 additions & 10 deletions include/exec/detail/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ namespace experimental::execution::__shared
////////////////////////////////////////////////////////////////////////////////////////
template <class _CvSender, class _Env>
using __result_variant_t =
__transform_completion_signatures_t<__completion_signatures_of_t<_CvSender, _Env>,
__mbind_front_q<__decayed_tuple, set_value_t>::__f,
__mbind_front_q<__decayed_tuple, set_error_t>::__f,
__tuple<set_stopped_t>,
__munique<__qq<__variant>>::__f,
__tuple<set_error_t, std::exception_ptr>,
__tuple<set_stopped_t>>;
__transform_reduce_completion_signatures_t<__completion_signatures_of_t<_CvSender, _Env>,
__mbind_front_q<__decayed_tuple, set_value_t>::__f,
__mbind_front_q<__decayed_tuple, set_error_t>::__f,
__tuple<set_stopped_t>,
__munique<__qq<__variant>>::__f,
__tuple<set_error_t, std::exception_ptr>,
__tuple<set_stopped_t>>;

////////////////////////////////////////////////////////////////////////////////////////
template <class _CvChild, class _Env>
Expand Down Expand Up @@ -461,12 +461,12 @@ namespace experimental::execution::__shared
};

template <class _Cv, class _CvSender, class _Env>
using __make_completions_t = __try_make_completion_signatures<
using __make_completions_t = __transform_completion_signatures_of_t<
_CvSender,
__env_t<_Env>,
completion_signatures<set_error_t(__mcall1<_Cv, std::exception_ptr>), set_stopped_t()>,
__mtransform<_Cv, __mcompose<__qq<completion_signatures>, __qf<set_value_t>>>,
__mtransform<_Cv, __mcompose<__qq<completion_signatures>, __qf<set_error_t>>>>;
__mtransform<_Cv, __mcompose<__qq<completion_signatures>, __qf<set_value_t>>>::template __f,
__mtransform<_Cv, __mcompose<__qq<completion_signatures>, __qf<set_error_t>>>::template __f>;

// split completes with const T&. ensure_started completes with T&&.
template <class _Tag>
Expand Down
2 changes: 1 addition & 1 deletion include/exec/into_tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace experimental::execution
STDEXEC::completion_signatures<set_error_t(std::exception_ptr), set_value_t(_Tuple)>;

template <class _Sender, class... _Env>
using __completions_t = transform_completion_signatures<
using __completions_t = __transform_completion_signatures_t<
__completion_signatures_of_t<_Sender, _Env...>,
__minvoke_q<__tuple_completions_t, __result_tuple_t<_Sender, _Env...>>,
__mconst<STDEXEC::completion_signatures<>>::__f>;
Expand Down
2 changes: 1 addition & 1 deletion include/exec/just_from.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace experimental::execution
{
template <class Fn>
using __f = STDEXEC::__concat_completion_signatures_t<STDEXEC::__call_result_t<Fn, _probe_fn>,
STDEXEC::__eptr_completion>;
STDEXEC::__eptr_completion_t>;
};

template <class Fn>
Expand Down
4 changes: 2 additions & 2 deletions include/exec/libdispatch_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ namespace experimental::execution
STDEXEC::__mbind_front_q<bulk_non_throwing_t, Fun, Shape>,
STDEXEC::__q<STDEXEC::__mand>>::value,
STDEXEC::completion_signatures<>,
STDEXEC::__eptr_completion>;
STDEXEC::__eptr_completion_t>;

template <class... Tys>
using set_value_t =
STDEXEC::completion_signatures<STDEXEC::set_value_t(STDEXEC::__decay_t<Tys>...)>;

template <class Self, class... Env>
using _completions_t = STDEXEC::transform_completion_signatures<
using _completions_t = STDEXEC::__transform_completion_signatures_t<
STDEXEC::__completion_signatures_of_t<STDEXEC::__copy_cvref_t<Self, Sender>, Env...>,
with_error_invoke_t<STDEXEC::__copy_cvref_t<Self, Sender>, Env...>,
set_value_t>;
Expand Down
4 changes: 2 additions & 2 deletions include/exec/materialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace experimental::execution
using __materialize_error = completion_signatures<set_value_t(set_error_t, _Err)>;

template <class _Self, class... _Env>
using __completions_t = __transform_completion_signatures_t<
using __completions_t = __transform_reduce_completion_signatures_t<
__completion_signatures_of_t<__copy_cvref_t<_Self, _Sender>, _Env...>,
__materialize_value,
__materialize_error,
Expand Down Expand Up @@ -202,7 +202,7 @@ namespace experimental::execution
using __dematerialize_value = completion_signatures<__decay_t<_Tag>(_Args...)>;

template <class _Self, class... _Env>
using __completions_t = transform_completion_signatures<
using __completions_t = __transform_completion_signatures_t<
__completion_signatures_of_t<__copy_cvref_t<_Self, _Sender>, _Env...>,
completion_signatures<>,
__mtry_q<__dematerialize_value>::template __f>;
Expand Down
8 changes: 4 additions & 4 deletions include/exec/repeat_n.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ namespace experimental::execution
using __error_t = completion_signatures<set_error_t(__decay_t<_Error>)>;

template <typename _Sender, typename... _Env>
using __with_eptr_completion_t = __eptr_completion_unless<
using __with_eptr_completion_t = __eptr_completion_unless_t<__mbool<
__cmplsigs::__partitions_of_t<
__completion_signatures_of_t<_Sender, _Env...>>::__nothrow_decay_copyable::__errors::value
&& (__nothrow_connectable<_Sender, __receiver_archetype<_Env>> && ...)>;
&& (__nothrow_connectable<_Sender, __receiver_archetype<_Env>> && ...)>>;

template <class _Child, class... _Env>
using __completions_t = STDEXEC::transform_completion_signatures<
using __completions_t = STDEXEC::__transform_completion_signatures_t<
__completion_signatures_of_t<_Child &, _Env...>,
STDEXEC::transform_completion_signatures<
STDEXEC::__transform_completion_signatures_t<
__completion_signatures_of_t<STDEXEC::schedule_result_t<trampoline_scheduler>, _Env...>,
__with_eptr_completion_t<_Child, _Env...>,
__cmplsigs::__default_set_value,
Expand Down
6 changes: 3 additions & 3 deletions include/exec/repeat_until.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ namespace experimental::execution
}
else
{
constexpr bool __has_nothrow_connect =
(__nothrow_connectable<__child_t, __receiver_archetype<_Env>> || ...);
constexpr auto __eptr_sigs = __eptr_completion_unless<__has_nothrow_connect>();
using __has_nothrow_connect_t =
__mbool<(__nothrow_connectable<__child_t, __receiver_archetype<_Env>> || ...)>;
constexpr auto __eptr_sigs = __eptr_completion_unless_t<__has_nothrow_connect_t>();
constexpr auto __bouncer_sigs = exec::transform_completion_signatures(
get_completion_signatures<__bouncer_t, _Env...>(),
exec::ignore_completion()); // drop the set_value_t() completion from the
Expand Down
8 changes: 4 additions & 4 deletions include/exec/sequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ namespace experimental::execution
}
else
{
using __env_t = STDEXEC::__mfront<Env..., STDEXEC::env<>>;
using __rcvr_t = STDEXEC::__receiver_archetype<__env_t>;
constexpr bool nothrow = (STDEXEC::__nothrow_connectable<Senders, __rcvr_t> && ...);
using __env_t = STDEXEC::__mfront<Env..., STDEXEC::env<>>;
using __rcvr_t = STDEXEC::__receiver_archetype<__env_t>;
constexpr bool __is_nothrow = (STDEXEC::__nothrow_connectable<Senders, __rcvr_t> && ...);

// The completions of the sequence sender are the error and stopped completions of all the
// child senders plus the value completions of the last child sender.
Expand All @@ -272,7 +272,7 @@ namespace experimental::execution
STDEXEC::get_completion_signatures<Senders, Env...>(),
exec::ignore_completion())...,
STDEXEC::get_completion_signatures<STDEXEC::__mback<Senders...>, Env...>(),
STDEXEC::__eptr_completion_unless<nothrow>());
STDEXEC::__eptr_completion_unless_t<STDEXEC::__mbool<__is_nothrow>>());
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/exec/sequence/ignore_all_values.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ namespace experimental::execution
};

template <class _Sigs>
using __result_variant_ = __transform_completion_signatures_t<
using __result_variant_ = __transform_reduce_completion_signatures_t<
_Sigs,
__mconst<__mlist<>>::__f,
__mcompose_q<__mlist, __mbind_front_q<__decayed_tuple, set_error_t>::__f>::__f,
Expand Down
Loading