YOrch 1.0.0
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <tuple>
5#include <type_traits>
6#include <utility>
7
8#include "../../context.hpp"
9#include "../../resolve.hpp"
10#include "../../slots.hpp"
11#include "../../task_adapters.hpp" // IWYU pragma: keep
12#include "../../detail/bind/member_receiver.hpp"
13#include "../../detail/bind/traits.hpp"
14
15namespace yorch {
16
27template <typename F, typename... Specs>
28struct bound_task {
31
34
36 std::tuple<Specs...> specs;
37
45 template <typename Ctx, typename Prev>
46 constexpr decltype(auto) invoke_raw(exec_context<Ctx, Prev>& ec)
47 noexcept(noexcept(call_impl_raw(ec, std::index_sequence_for<Specs...>{}))) {
48 return call_impl_raw(ec, std::index_sequence_for<Specs...>{});
49 }
50
51private:
52 template <typename Ctx, typename Prev, std::size_t... I>
53 constexpr decltype(auto) call_impl_raw(exec_context<Ctx, Prev>& ec, std::index_sequence<I...>)
54 noexcept(noexcept(std::invoke(
55 func,
56 resolve_as<detail::nth_arg_t<I, F>>(std::get<I>(specs), ec)...))) {
57 return std::invoke(
58 func,
59 resolve_as<detail::nth_arg_t<I, F>>(std::get<I>(specs), ec)...
60 );
61 }
62};
63
75template <typename F, typename T, typename... Specs>
78 using output_type = T;
80
82 std::tuple<Specs...> specs;
83
84 template <typename Ctx, typename Prev>
86 noexcept(noexcept(call_impl_into(ec, out, std::index_sequence_for<Specs...> {}))) {
87 using call_result_t =
88 decltype(call_impl_into(ec, out, std::index_sequence_for<Specs...> {}));
89
90 if constexpr (std::is_void_v<call_result_t>) {
91 call_impl_into(ec, out, std::index_sequence_for<Specs...> {});
92 return step_result::success();
93 } else {
94 static_assert(std::is_same_v<std::remove_cvref_t<call_result_t>, step_result>,
95 "bind_into(...) callable must return void or yorch::step_result");
96 return call_impl_into(ec, out, std::index_sequence_for<Specs...> {});
97 }
98 }
99
100private:
101 template <typename Ctx, typename Prev, std::size_t... I>
102 constexpr decltype(auto) call_impl_into(
103 exec_context<Ctx, Prev>& ec,
104 direct_out<T> out,
105 std::index_sequence<I...>)
106 noexcept(noexcept(std::invoke(
107 func,
108 resolve_as<detail::nth_arg_t<I, F>>(std::get<I>(specs), ec)...,
109 out))) {
110 return std::invoke(
111 func,
112 resolve_as<detail::nth_arg_t<I, F>>(std::get<I>(specs), ec)...,
113 out);
114 }
115};
116
117template <typename F, typename T, typename... Specs>
120 using output_type = T;
122
124 std::tuple<Specs...> specs;
125
126 template <typename Ctx, typename Prev>
128 noexcept(noexcept(call_impl_raw(ec, std::index_sequence_for<Specs...> {}))) {
129 using call_result_t =
130 decltype(call_impl_raw(ec, std::index_sequence_for<Specs...> {}));
131
132 if constexpr (std::is_void_v<call_result_t>) {
133 call_impl_raw(ec, std::index_sequence_for<Specs...> {});
134 return step_result::success();
135 } else {
136 static_assert(std::is_same_v<std::remove_cvref_t<call_result_t>, step_result>,
137 "bind_forward_prev(...) callable must return void or yorch::step_result");
138 return call_impl_raw(ec, std::index_sequence_for<Specs...> {});
139 }
140 }
141
142private:
143 template <typename Ctx, typename Prev, std::size_t... I>
144 constexpr decltype(auto) call_impl_raw(
145 exec_context<Ctx, Prev>& ec,
146 std::index_sequence<I...>)
147 noexcept(noexcept(std::invoke(
148 func,
149 resolve_as<detail::nth_arg_t<I, F>>(std::get<I>(specs), ec)...))) {
150 return std::invoke(
151 func,
152 resolve_as<detail::nth_arg_t<I, F>>(std::get<I>(specs), ec)...);
153 }
154};
155
156template <typename F, typename ReceiverSpec, typename T, typename... Specs>
159 using output_type = T;
161
163 ReceiverSpec receiver_spec;
164 std::tuple<Specs...> specs;
165
166 template <typename Ctx, typename Prev>
168 noexcept(noexcept(call_impl_raw(ec, std::index_sequence_for<Specs...> {}))) {
169 using call_result_t =
170 decltype(call_impl_raw(ec, std::index_sequence_for<Specs...> {}));
171
172 if constexpr (std::is_void_v<call_result_t>) {
173 call_impl_raw(ec, std::index_sequence_for<Specs...> {});
174 return step_result::success();
175 } else {
176 static_assert(std::is_same_v<std::remove_cvref_t<call_result_t>, step_result>,
177 "bind_forward_prev_member(...) callable must return void or yorch::step_result");
178 return call_impl_raw(ec, std::index_sequence_for<Specs...> {});
179 }
180 }
181
182private:
183 template <typename Ctx, typename Prev, std::size_t... I>
184 constexpr decltype(auto) call_impl_raw(
185 exec_context<Ctx, Prev>& ec,
186 std::index_sequence<I...>)
187 noexcept(noexcept(detail::invoke_member_with_receiver(
188 func,
190 resolve_as<detail::member_nth_arg_t<I, F>>(std::get<I>(specs), ec)...))) {
193 func,
194 std::move(receiver),
195 resolve_as<detail::member_nth_arg_t<I, F>>(std::get<I>(specs), ec)...);
196 }
197};
198
212template <typename F, typename ReceiverSpec, typename... Specs>
215
217 ReceiverSpec receiver_spec;
218 std::tuple<Specs...> specs;
219
220 template <typename Ctx, typename Prev>
221 constexpr decltype(auto) invoke_raw(exec_context<Ctx, Prev>& ec)
222 noexcept(noexcept(call_impl_raw(ec, std::index_sequence_for<Specs...>{}))) {
223 return call_impl_raw(ec, std::index_sequence_for<Specs...>{});
224 }
225
226private:
227 template <typename Ctx, typename Prev, std::size_t... I>
228 constexpr decltype(auto) call_impl_raw(exec_context<Ctx, Prev>& ec, std::index_sequence<I...>)
229 noexcept(noexcept(detail::invoke_member_with_receiver(
230 func,
232 resolve_as<detail::member_nth_arg_t<I, F>>(std::get<I>(specs), ec)...))) {
235 func,
236 std::move(receiver),
237 resolve_as<detail::member_nth_arg_t<I, F>>(std::get<I>(specs), ec)...);
238 }
239};
240
254template <typename F, typename ReceiverSpec, typename T, typename... Specs>
257 using output_type = T;
259
261 ReceiverSpec receiver_spec;
262 std::tuple<Specs...> specs;
263
264 template <typename Ctx, typename Prev>
266 noexcept(noexcept(call_impl_into(ec, out, std::index_sequence_for<Specs...> {}))) {
267 using call_result_t =
268 decltype(call_impl_into(ec, out, std::index_sequence_for<Specs...> {}));
269
270 if constexpr (std::is_void_v<call_result_t>) {
271 call_impl_into(ec, out, std::index_sequence_for<Specs...> {});
272 return step_result::success();
273 } else {
274 static_assert(std::is_same_v<std::remove_cvref_t<call_result_t>, step_result>,
275 "bind_into_member(...) callable must return void or yorch::step_result");
276 return call_impl_into(ec, out, std::index_sequence_for<Specs...> {});
277 }
278 }
279
280private:
281 template <typename Ctx, typename Prev, std::size_t... I>
282 constexpr decltype(auto) call_impl_into(
283 exec_context<Ctx, Prev>& ec,
284 direct_out<T> out,
285 std::index_sequence<I...>)
286 noexcept(noexcept(detail::invoke_member_with_receiver(
287 func,
289 resolve_as<detail::member_nth_arg_t<I, F>>(std::get<I>(specs), ec)...,
290 out))) {
293 func,
294 std::move(receiver),
295 resolve_as<detail::member_nth_arg_t<I, F>>(std::get<I>(specs), ec)...,
296 out);
297 }
298};
299
300} // namespace yorch
typename member_function_traits< std::remove_cvref_t< F > >::result_type member_result_t
Definition traits.hpp:125
typename function_traits< std::remove_cvref_t< F > >::result_type result_t
Definition traits.hpp:121
constexpr bool is_adapter_descriptor_v
Definition adapters.hpp:63
constexpr decltype(auto) invoke_member_with_receiver(F &&func, Receiver &&receiver, Args &&... args) noexcept(noexcept(std::invoke(std::forward< F >(func), forward_member_receiver(std::forward< Receiver >(receiver)), std::forward< Args >(args)...)))
constexpr decltype(auto) resolve_as(from_ctx_t< T >, exec_context< Ctx, Prev > &ec) noexcept(detail::resolve_from_ctx_nothrow_v< Arg, T, Ctx >)
Resolves a from_ctx(...) spec by fetching the requested object from the execution context and binding...
Definition resolve.hpp:191
std::tuple< Specs... > specs
Definition types.hpp:124
constexpr step_result invoke_raw(exec_context< Ctx, Prev > &ec) noexcept(noexcept(call_impl_raw(ec, std::index_sequence_for< Specs... > {})))
Definition types.hpp:127
std::tuple< Specs... > specs
Definition types.hpp:164
constexpr step_result invoke_raw(exec_context< Ctx, Prev > &ec) noexcept(noexcept(call_impl_raw(ec, std::index_sequence_for< Specs... > {})))
Definition types.hpp:167
Bound direct-output task composed of a member function, receiver spec, and non-output parameter specs...
Definition types.hpp:255
constexpr step_result invoke_into(exec_context< Ctx, Prev > &ec, direct_out< T > out) noexcept(noexcept(call_impl_into(ec, out, std::index_sequence_for< Specs... > {})))
Definition types.hpp:265
std::tuple< Specs... > specs
Definition types.hpp:262
Bound executable task composed of a member function, receiver spec, and per-parameter specs.
Definition types.hpp:213
detail::member_result_t< F > raw_result_type
Definition types.hpp:214
ReceiverSpec receiver_spec
Definition types.hpp:217
std::tuple< Specs... > specs
Definition types.hpp:218
constexpr decltype(auto) invoke_raw(exec_context< Ctx, Prev > &ec) noexcept(noexcept(call_impl_raw(ec, std::index_sequence_for< Specs... >{})))
Definition types.hpp:221
Bound direct-output task that writes its payload into a provided slot.
Definition types.hpp:76
constexpr step_result invoke_into(exec_context< Ctx, Prev > &ec, direct_out< T > out) noexcept(noexcept(call_impl_into(ec, out, std::index_sequence_for< Specs... > {})))
Definition types.hpp:85
std::tuple< Specs... > specs
Definition types.hpp:82
Bound executable task composed of a callable and per-parameter specs.
Definition types.hpp:28
F func
Stored callable to execute.
Definition types.hpp:33
constexpr decltype(auto) invoke_raw(exec_context< Ctx, Prev > &ec) noexcept(noexcept(call_impl_raw(ec, std::index_sequence_for< Specs... >{})))
Resolves all specs and executes the bound callable.
Definition types.hpp:46
detail::result_t< F > raw_result_type
Raw return type declared by the stored callable.
Definition types.hpp:30
std::tuple< Specs... > specs
Stored argument binding specs in parameter order.
Definition types.hpp:36
Output sink passed to direct-output tasks.
Lightweight borrowed view used during execution.
Definition context.hpp:187
Represents the basic outcome of a task step.
Definition result.hpp:42
static constexpr step_result success() noexcept
Creates a successful result.
Definition result.hpp:46