|
18 | 18 | #include "../stdexec/__detail/__get_completion_signatures.hpp" |
19 | 19 | #include "../stdexec/__detail/__meta.hpp" |
20 | 20 | #include "../stdexec/__detail/__sender_concepts.hpp" |
21 | | -#include "../stdexec/__detail/__tuple.hpp" // IWYU pragma: keep for STDEXEC::__tuple |
| 21 | +#include "../stdexec/__detail/__transform_completion_signatures.hpp" |
22 | 22 |
|
23 | 23 | namespace exec { |
24 | 24 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
@@ -77,173 +77,46 @@ namespace exec { |
77 | 77 | return {}; |
78 | 78 | } |
79 | 79 |
|
80 | | - STDEXEC_PRAGMA_PUSH() |
81 | | - STDEXEC_PRAGMA_IGNORE_EDG(expr_has_no_effect) |
82 | | - STDEXEC_PRAGMA_IGNORE_GNU("-Wunused-value") |
83 | | - |
84 | 80 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
85 | 81 | // concat_completion_signatures |
86 | | - namespace detail { |
87 | | - struct concat_completion_signatures_t { |
88 | | - template <STDEXEC::__valid_completion_signatures... Sigs> |
89 | | - [[nodiscard]] |
90 | | - consteval auto operator()(Sigs...) const noexcept // |
91 | | - -> STDEXEC::__concat_completion_signatures<Sigs...> { |
92 | | - return {}; |
93 | | - } |
94 | | - |
95 | | - template <class... Errors> |
96 | | - [[nodiscard]] |
97 | | - consteval auto operator()(Errors...) const noexcept { |
98 | | - return (Errors{}, ...); // NB: uses overloaded comma operator on _ERROR_ type to produce an |
99 | | - // error type |
100 | | - } |
101 | | - }; |
102 | | - } // namespace detail |
103 | | - |
104 | | - inline constexpr detail::concat_completion_signatures_t concat_completion_signatures{}; |
105 | | - |
106 | | - STDEXEC_PRAGMA_POP() |
| 82 | + inline constexpr STDEXEC::__detail::__concat_completion_signatures_fn |
| 83 | + concat_completion_signatures{}; |
107 | 84 |
|
108 | 85 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
109 | | - // invalid_completion_signature |
| 86 | + // throw_compile_time_error |
110 | 87 | template <class... What, class... Values> |
111 | 88 | [[nodiscard]] |
112 | | - consteval auto invalid_completion_signature(Values... vals) { |
113 | | - return STDEXEC::__invalid_completion_signature<What...>(static_cast<Values&&>(vals)...); |
| 89 | + consteval auto throw_compile_time_error(Values... vals) { |
| 90 | + return STDEXEC::__throw_compile_time_error<What...>(static_cast<Values&&>(vals)...); |
114 | 91 | } |
115 | 92 |
|
116 | | - struct IN_TRANSFORM_COMPLETION_SIGNATURES; |
117 | | - struct A_TRANSFORM_FUNCTION_RETURNED_A_TYPE_THAT_IS_NOT_A_COMPLETION_SIGNATURES_SPECIALIZATION; |
118 | | - struct COULD_NOT_CALL_THE_TRANSFORM_FUNCTION_WITH_THE_GIVEN_TEMPLATE_ARGUMENTS; |
119 | | - |
120 | | - namespace detail { |
121 | | - template <class Fn, class... As> |
122 | | - using meta_call_result_t = decltype(STDEXEC::__declval<Fn>().template operator()<As...>()); |
123 | | - |
124 | | - template <class Ay, class... As, class Fn> |
125 | | - [[nodiscard]] |
126 | | - consteval auto _transform_expr(const Fn& fn) -> meta_call_result_t<const Fn&, Ay, As...> { |
127 | | - return fn.template operator()<Ay, As...>(); |
128 | | - } |
129 | | - |
130 | | - template <class Fn> |
131 | | - [[nodiscard]] |
132 | | - consteval auto _transform_expr(const Fn& fn) -> STDEXEC::__call_result_t<const Fn&> { |
133 | | - return fn(); |
134 | | - } |
135 | | - |
136 | | - template <class Fn, class... As> |
137 | | - using _transform_expr_t = decltype(detail::_transform_expr<As...>( |
138 | | - STDEXEC::__declval<const Fn&>())); |
139 | | - |
140 | | - // transform_completion_signatures: |
141 | | - template <class... As, class Fn> |
142 | | - [[nodiscard]] |
143 | | - consteval auto _apply_transform(const Fn& fn) { |
144 | | - if constexpr (STDEXEC::__mvalid<_transform_expr_t, Fn, As...>) { |
145 | | - using _completions_t = _transform_expr_t<Fn, As...>; |
146 | | - if constexpr (STDEXEC::__well_formed_completions<_completions_t>) { |
147 | | - return detail::_transform_expr<As...>(fn); |
148 | | - } else { |
149 | | - (void) detail::_transform_expr<As...>(fn); // potentially throwing |
150 | | - return invalid_completion_signature< |
151 | | - IN_TRANSFORM_COMPLETION_SIGNATURES, |
152 | | - A_TRANSFORM_FUNCTION_RETURNED_A_TYPE_THAT_IS_NOT_A_COMPLETION_SIGNATURES_SPECIALIZATION, |
153 | | - STDEXEC::_WITH_FUNCTION_<Fn>, |
154 | | - STDEXEC::_WITH_ARGUMENTS_<As...> |
155 | | - >(); |
156 | | - } |
157 | | - } else { |
158 | | - return invalid_completion_signature< |
159 | | - IN_TRANSFORM_COMPLETION_SIGNATURES, |
160 | | - COULD_NOT_CALL_THE_TRANSFORM_FUNCTION_WITH_THE_GIVEN_TEMPLATE_ARGUMENTS, |
161 | | - STDEXEC::_WITH_FUNCTION_<Fn>, |
162 | | - STDEXEC::_WITH_ARGUMENTS_<As...> |
163 | | - >(); |
164 | | - } |
165 | | - } |
166 | | - |
167 | | - template <class ValueFn, class ErrorFn, class StoppedFn> |
168 | | - struct _transform_one { |
169 | | - ValueFn value_fn; |
170 | | - ErrorFn error_fn; |
171 | | - StoppedFn stopped_fn; |
172 | | - |
173 | | - template <class Tag, class... Ts> |
174 | | - [[nodiscard]] |
175 | | - consteval auto operator()(Tag (*)(Ts...)) const { |
176 | | - if constexpr (Tag{} == STDEXEC::set_value) { |
177 | | - return detail::_apply_transform<Ts...>(value_fn); |
178 | | - } else if constexpr (Tag{} == STDEXEC::set_error) { |
179 | | - return detail::_apply_transform<Ts...>(error_fn); |
180 | | - } else { |
181 | | - return detail::_apply_transform<Ts...>(stopped_fn); |
182 | | - } |
183 | | - } |
184 | | - }; |
185 | | - |
186 | | - template <class TransformOne> |
187 | | - struct _transform_all_fn { |
188 | | - TransformOne tfx1; |
189 | | - |
190 | | - template <class... Sigs> |
191 | | - [[nodiscard]] |
192 | | - consteval auto operator()(Sigs*... sigs) const { |
193 | | - return concat_completion_signatures(tfx1(sigs)...); |
194 | | - } |
195 | | - }; |
196 | | - |
197 | | - template <class TransformOne> |
198 | | - _transform_all_fn(TransformOne) -> _transform_all_fn<TransformOne>; |
199 | | - } // namespace detail |
200 | | - |
201 | | - template <class Tag> |
202 | | - struct keep_completion { |
203 | | - template <class... Ts> |
204 | | - consteval auto operator()() const noexcept -> STDEXEC::completion_signatures<Tag(Ts...)> { |
205 | | - return {}; |
206 | | - } |
207 | | - }; |
| 93 | + ////////////////////////////////////////////////////////////////////////////////////////////////// |
| 94 | + // transform_completion_signatures |
| 95 | + template <class _SetTag> |
| 96 | + using keep_completion = STDEXEC::__keep_completion<_SetTag>; |
208 | 97 |
|
209 | | - struct ignore_completion { |
210 | | - template <class... Ts> |
211 | | - consteval auto operator()() const noexcept -> STDEXEC::completion_signatures<> { |
212 | | - return {}; |
213 | | - } |
214 | | - }; |
| 98 | + using ignore_completion = STDEXEC::__ignore_completion; |
215 | 99 |
|
216 | | - template <class Tag, class Fn> |
217 | | - struct transform_arguments { |
218 | | - template <class... Ts> |
219 | | - consteval auto operator()() const noexcept |
220 | | - -> STDEXEC::completion_signatures<Tag(STDEXEC::__minvoke<Fn, Ts>...)> { |
221 | | - return {}; |
222 | | - } |
223 | | - }; |
| 100 | + template <class _SetTag, class _Fn, class... _AlgoTag> |
| 101 | + using transform_arguments = STDEXEC::__transform_arguments<_SetTag, _Fn, _AlgoTag...>; |
224 | 102 |
|
225 | | - template <class Tag> |
226 | | - struct decay_arguments : transform_arguments<Tag, STDEXEC::__q1<STDEXEC::__decay_t>> { }; |
| 103 | + template <class _SetTag, class... _AlgoTag> |
| 104 | + using decay_arguments = STDEXEC::__decay_arguments<_SetTag, _AlgoTag...>; |
227 | 105 |
|
228 | 106 | template < |
229 | | - class Completions, |
230 | | - class ValueFn = keep_completion<STDEXEC::set_value_t>, |
231 | | - class ErrorFn = keep_completion<STDEXEC::set_error_t>, |
232 | | - class StoppedFn = keep_completion<STDEXEC::set_stopped_t>, |
233 | | - class ExtraSigs = STDEXEC::completion_signatures<> |
| 107 | + class _Completions, |
| 108 | + class _ValueFn = keep_completion<STDEXEC::set_value_t>, |
| 109 | + class _ErrorFn = keep_completion<STDEXEC::set_error_t>, |
| 110 | + class _StoppedFn = keep_completion<STDEXEC::set_stopped_t>, |
| 111 | + class _ExtraSigs = STDEXEC::completion_signatures<> |
234 | 112 | > |
235 | 113 | consteval auto transform_completion_signatures( |
236 | | - Completions, |
237 | | - ValueFn value_fn = {}, |
238 | | - ErrorFn error_fn = {}, |
239 | | - StoppedFn stopped_fn = {}, |
240 | | - ExtraSigs = {}) { |
241 | | - STDEXEC_COMPLSIGS_LET(completions, Completions{}) { |
242 | | - STDEXEC_COMPLSIGS_LET(extra_sigs, ExtraSigs{}) { |
243 | | - detail::_transform_one<ValueFn, ErrorFn, StoppedFn> tfx1{value_fn, error_fn, stopped_fn}; |
244 | | - return concat_completion_signatures( |
245 | | - completions.__apply(detail::_transform_all_fn{tfx1}), extra_sigs); |
246 | | - } |
247 | | - } |
| 114 | + _Completions, |
| 115 | + _ValueFn __value_fn = {}, |
| 116 | + _ErrorFn __error_fn = {}, |
| 117 | + _StoppedFn __stopped_fn = {}, |
| 118 | + _ExtraSigs = {}) { |
| 119 | + return STDEXEC::__transform_completion_signatures( |
| 120 | + _Completions{}, __value_fn, __error_fn, __stopped_fn, _ExtraSigs{}); |
248 | 121 | } |
249 | 122 | } // namespace exec |
0 commit comments