@@ -58,19 +58,25 @@ namespace experimental::execution
5858 // ! by combining explicitly provided signature types with those deduced from pointer
5959 // ! arguments.
6060 // !
61- // ! @tparam ExplicitSigs Explicitly specified completion signature types.
62- // ! @tparam DeducedSigs Completion signature types to be deduced from the function arguments.
63- // ! @param unnamed Pointer arguments (unused) used for type deduction of DeducedSigs.
61+ // ! \tparam ExplicitSigs Explicitly specified completion signature types. Must be a pack
62+ // ! of function types, the returns types of which must be one of
63+ // ! \c set_value_t, \c set_error_t, or \c set_stopped_t.
64+ // ! \tparam DeducedSigs Completion signature types to be deduced from the function
65+ // ! arguments.
66+ // ! \param unnamed Pointer arguments (unused) for type deduction of
67+ // ! \c DeducedSigs. Must be a pack of function pointer types, the
68+ // ! returns types of which must be one of \c set_value_t,
69+ // ! \c set_error_t, or \c set_stopped_t.
6470 // !
65- // ! @ return An instance of ` STDEXEC::completion_signatures` containing the combined
71+ // ! \ return An instance of \c STDEXEC::completion_signatures containing the combined
6672 // ! signatures.
6773 // !
68- // ! @ note This is a ` consteval` function, meaning it is only callable in constant evaluation
69- // ! contexts (compile-time). It always returns a default-constructed instance of the result
70- // ! type.
74+ // ! \ note This is a \c consteval function, meaning it is only callable in constant
75+ // ! evaluation contexts (compile-time). It always returns a default-constructed
76+ // ! instance of the result type.
7177 // !
72- // ! @ note The function uses pointer arguments for type deduction without requiring actual object
73- // ! instances.
78+ // ! \ note The function uses pointer arguments for type deduction without requiring
79+ // ! actual object instances.
7480 template <class ... ExplicitSigs, class ... DeducedSigs>
7581 [[nodiscard]]
7682 consteval auto make_completion_signatures (DeducedSigs*...) noexcept
@@ -95,33 +101,134 @@ namespace experimental::execution
95101
96102 // ////////////////////////////////////////////////////////////////////////////////////////////////
97103 // transform_completion_signatures
104+
98105 template <class _SetTag >
99106 using keep_completion = STDEXEC::__keep_completion<_SetTag>;
100107
101108 using ignore_completion = STDEXEC::__ignore_completion;
102109
103- template <class _SetTag , class _Fn , class ... _AlgoTag>
104- using transform_arguments = STDEXEC::__transform_arguments<_SetTag, _Fn, _AlgoTag...>;
110+ template <class _SetTag , template <class > class _Fn , class ... _AlgoTag>
111+ using transform_arguments =
112+ STDEXEC::__transform_arguments<_SetTag, STDEXEC::__q1<_Fn>, _AlgoTag...>;
105113
106114 template <class _SetTag , class ... _AlgoTag>
107115 using decay_arguments = STDEXEC::__decay_arguments<_SetTag, _AlgoTag...>;
108116
109- template <class _Completions ,
110- class _ValueFn = keep_completion<STDEXEC::set_value_t >,
111- class _ErrorFn = keep_completion<STDEXEC::set_error_t >,
112- class _StoppedFn = keep_completion<STDEXEC::set_stopped_t >,
113- class _ExtraSigs = STDEXEC::completion_signatures<>>
114- consteval auto transform_completion_signatures (_Completions,
115- _ValueFn __value_fn = {},
116- _ErrorFn __error_fn = {},
117- _StoppedFn __stopped_fn = {},
118- _ExtraSigs = {})
117+ // ! \brief Transforms completion signatures using provided transformation functions.
118+ // !
119+ // ! This consteval function transforms a set of completion signatures by applying
120+ // ! custom transformation functions to value, error, and stopped completion cases.
121+ // ! The result can be augmented with additional extra signatures.
122+ // !
123+ // ! \tparam Completions The input completion signatures to transform. Must be a
124+ // ! specialization of \c STDEXEC::completion_signatures.
125+ // ! \tparam ValueFn Function object that transforms set_value_t completions.
126+ // ! Defaults to keep_completion<set_value_t>.
127+ // ! \tparam ErrorFn Function object that transforms set_error_t completions.
128+ // ! Defaults to keep_completion<set_error_t>.
129+ // ! \tparam StoppedFn Function object that transforms set_stopped_t completions.
130+ // ! Defaults to keep_completion<set_stopped_t>.
131+ // ! \tparam ExtraSigs Additional completion signatures to append to the result.
132+ // ! Must be a specialization of \c STDEXEC::completion_signatures.
133+ // ! Defaults to \c STDEXEC::completion_signatures().
134+ // !
135+ // ! \param completions The input completion signatures object.
136+ // ! \param value_fn Value transformation function instance.
137+ // ! \param error_fn Error transformation function instance.
138+ // ! \param stopped_fn Stopped transformation function instance.
139+ // ! \param extra_sigs Extra signatures to append to the result.
140+ // !
141+ // ! \return A transformed completion_signatures object combining the transformed
142+ // ! input signatures with the extra signatures.
143+ // !
144+ // ! \par Example
145+ // !
146+ // ! The following example demonstrates how to use \c transform_completion_signatures
147+ // ! to compute the completion signatures of the \c then sender.
148+ // !
149+ // ! \code{.cpp}
150+ // ! namespace ex = STDEXEC;
151+ // !
152+ // ! // A helper function to transform the value types of the child sender into the value
153+ // ! // types of the then sender.
154+ // ! template <class Fn, class... Args>
155+ // ! consteval auto _transform_values()
156+ // ! {
157+ // ! if constexpr (!std::invocable<Fn, Args...>)
158+ // ! {
159+ // ! // If Fn cannot be invoked with the given arguments, produce a compile-time
160+ // ! // error.
161+ // ! return exec::throw_compile_time_error<
162+ // ! WHAT(FUNCTION_IS_NOT_CALLABLE_WITH_THE_GIVEN_ARGUMENTS),
163+ // ! WHERE(IN_ALGORITHM, then_t),
164+ // ! WITH_FUNCTION(Fn),
165+ // ! WITH_ARGUMENTS(Args...)>();
166+ // ! }
167+ // ! else
168+ // ! {
169+ // ! // transform the value types of the child sender into the value types of the
170+ // ! // then sender by applying Fn to them.
171+ // ! using result_t = std::invoke_result_t<Fn, Args...>;
172+ // ! constexpr bool is_void = std::is_void_v<result_t>;
173+ // ! constexpr bool nothrow = std::is_nothrow_invocable_v<Fn, Args...>;
174+ // ! if constexpr (is_void && nothrow)
175+ // ! {
176+ // ! return ex::completion_signatures<set_value_t()>();
177+ // ! }
178+ // ! else if constexpr (is_void && !nothrow)
179+ // ! {
180+ // ! return ex::completion_signatures<set_value_t(),
181+ // ! set_error_t(std::exception_ptr)>();
182+ // ! }
183+ // ! else if constexpr (!is_void && nothrow)
184+ // ! {
185+ // ! return ex::completion_signatures<set_value_t(result_t)>();
186+ // ! }
187+ // ! else /* !is_void && !nothrow */
188+ // ! {
189+ // ! return ex::completion_signatures<set_value_t(result_t),
190+ // ! set_error_t(std::exception_ptr)>();
191+ // ! }
192+ // ! }
193+ // ! }
194+ // !
195+ // ! template <class Child, class Fn>
196+ // ! struct then_sender
197+ // ! {
198+ // ! using sender_concept = ex::sender_t;
199+ // !
200+ // ! template <class Self, class... Env>
201+ // ! static consteval auto get_completion_signatures()
202+ // ! {
203+ // ! // Compute the completion signatures of the child sender, and then transform
204+ // ! // them into the completion signatures of the `then` sender.
205+ // ! auto child_completions = exec::get_child_completion_signatures<Self, Child, Env...>();
206+ // ! auto value_fn = []<class... Args>() { return _transform_values<Fn, Args...>(); };
207+ // !
208+ // ! return exec::transform_completion_signatures(child_completions, value_fn);
209+ // ! }
210+ // !
211+ // ! // ...
212+ // ! };
213+ // ! \endcode
214+ // !
215+ // ! \note This function is evaluated at compile-time (consteval).
216+ template <class Completions ,
217+ class ValueFn = keep_completion<STDEXEC::set_value_t >,
218+ class ErrorFn = keep_completion<STDEXEC::set_error_t >,
219+ class StoppedFn = keep_completion<STDEXEC::set_stopped_t >,
220+ class ExtraSigs = STDEXEC::completion_signatures<>>
221+ consteval auto transform_completion_signatures (Completions,
222+ ValueFn value_fn = {},
223+ ErrorFn error_fn = {},
224+ StoppedFn stopped_fn = {},
225+ ExtraSigs = {})
119226 {
120- return STDEXEC::__transform_completion_signatures (_Completions {},
121- __value_fn ,
122- __error_fn ,
123- __stopped_fn ,
124- _ExtraSigs {});
227+ return STDEXEC::__transform_completion_signatures (Completions {},
228+ value_fn ,
229+ error_fn ,
230+ stopped_fn ,
231+ ExtraSigs {});
125232 }
126233} // namespace experimental::execution
127234
0 commit comments