13 #ifndef __PROCESS_DEFERRED_HPP__ 14 #define __PROCESS_DEFERRED_HPP__ 42 template <
typename R,
typename T>
46 template <
typename R,
typename T>
50 Deferred(
const std::function<F>&
f) :
std::function<F>(f) {}
79 return std::function<void()>(std::forward<F>(
f));
85 F&& f_ = std::forward<F>(
f);
87 return std::function<void()>(
93 operator std::function<void()>() &&
96 return std::function<void()>(std::forward<F>(
f));
100 F&& f_ = std::forward<F>(
f);
102 return std::function<void()>(
121 std::forward<F>(
f)));
124 template <
typename R>
128 return std::function<R()>(std::forward<F>(
f));
132 F&& f_ = std::forward<F>(
f);
134 return std::function<R()>(
140 template <
typename R>
141 operator std::function<R()>() &&
144 return std::function<R()>(std::forward<F>(
f));
148 F&& f_ = std::forward<F>(
f);
150 return std::function<R()>(
156 template <
typename R>
170 std::forward<F>(
f)));
174 #define PLACEHOLDER(Z, N, DATA) CAT(lambda::_, INC(N)) 177 #define FORWARD(Z, N, DATA) std::forward<P ## N>(p ## N) 185 #define TEMPLATE(Z, N, DATA) \ 186 template <ENUM_PARAMS(N, typename P)> \ 187 operator Deferred<void(ENUM_PARAMS(N, P))>() && \ 189 if (pid.isNone()) { \ 190 return std::function<void(ENUM_PARAMS(N, P))>(std::forward<F>(f)); \ 193 Option<UPID> pid_ = pid; \ 194 F&& f_ = std::forward<F>(f); \ 196 return std::function<void(ENUM_PARAMS(N, P))>( \ 197 [=](ENUM_BINARY_PARAMS(N, P, p)) { \ 198 std::function<void()> f__([=]() { \ 199 f_(ENUM_PARAMS(N, p)); \ 201 dispatch(pid_.get(), f__); \ 205 template <ENUM_PARAMS(N, typename P)> \ 206 operator std::function<void(ENUM_PARAMS(N, P))>() && \ 208 if (pid.isNone()) { \ 209 return std::function<void(ENUM_PARAMS(N, P))>(std::forward<F>(f)); \ 212 Option<UPID> pid_ = pid; \ 213 F&& f_ = std::forward<F>(f); \ 215 return std::function<void(ENUM_PARAMS(N, P))>( \ 216 [=](ENUM_BINARY_PARAMS(N, P, p)) { \ 217 std::function<void()> f__([=]() { \ 218 f_(ENUM_PARAMS(N, p)); \ 220 dispatch(pid_.get(), f__); \ 224 template <ENUM_PARAMS(N, typename P)> \ 225 operator lambda::CallableOnce<void(ENUM_PARAMS(N, P))>() && \ 227 if (pid.isNone()) { \ 228 return lambda::CallableOnce<void(ENUM_PARAMS(N, P))>( \ 229 std::forward<F>(f)); \ 232 Option<UPID> pid_ = pid; \ 234 return lambda::CallableOnce<void(ENUM_PARAMS(N, P))>( \ 236 [pid_](typename std::decay<F>::type&& f_, \ 237 ENUM_BINARY_PARAMS(N, P, &&p)) { \ 238 lambda::CallableOnce<void()> f__( \ 239 lambda::partial(std::move(f_), ENUM(N, FORWARD, _))); \ 240 dispatch(pid_.get(), std::move(f__)); \ 242 std::forward<F>(f), \ 243 ENUM(N, PLACEHOLDER, _))); \ 249 #define TEMPLATE(Z, N, DATA) \ 250 template <typename R, ENUM_PARAMS(N, typename P)> \ 251 operator Deferred<R(ENUM_PARAMS(N, P))>() && \ 253 if (pid.isNone()) { \ 254 return std::function<R(ENUM_PARAMS(N, P))>(std::forward<F>(f)); \ 257 Option<UPID> pid_ = pid; \ 258 F&& f_ = std::forward<F>(f); \ 260 return std::function<R(ENUM_PARAMS(N, P))>( \ 261 [=](ENUM_BINARY_PARAMS(N, P, p)) { \ 262 std::function<R()> f__([=]() { \ 263 return f_(ENUM_PARAMS(N, p)); \ 265 return dispatch(pid_.get(), f__); \ 269 template <typename R, ENUM_PARAMS(N, typename P)> \ 270 operator std::function<R(ENUM_PARAMS(N, P))>() && \ 272 if (pid.isNone()) { \ 273 return std::function<R(ENUM_PARAMS(N, P))>(std::forward<F>(f)); \ 276 Option<UPID> pid_ = pid; \ 277 F&& f_ = std::forward<F>(f); \ 279 return std::function<R(ENUM_PARAMS(N, P))>( \ 280 [=](ENUM_BINARY_PARAMS(N, P, p)) { \ 281 std::function<R()> f__([=]() { \ 282 return f_(ENUM_PARAMS(N, p)); \ 284 return dispatch(pid_.get(), f__); \ 288 template <typename R, ENUM_PARAMS(N, typename P)> \ 289 operator lambda::CallableOnce<R(ENUM_PARAMS(N, P))>() && \ 291 if (pid.isNone()) { \ 292 return lambda::CallableOnce<R(ENUM_PARAMS(N, P))>( \ 293 std::forward<F>(f)); \ 296 Option<UPID> pid_ = pid; \ 298 return lambda::CallableOnce<R(ENUM_PARAMS(N, P))>( \ 300 [pid_](typename std::decay<F>::type&& f_, \ 301 ENUM_BINARY_PARAMS(N, P, &&p)) { \ 302 lambda::CallableOnce<R()> f__( \ 303 lambda::partial(std::move(f_), ENUM(N, FORWARD, _))); \ 304 return dispatch(pid_.get(), std::move(f__)); \ 306 std::forward<F>(f), \ 307 ENUM(N, PLACEHOLDER, _))); \ 319 template <
typename G>
323 #define FORWARD(Z, N, DATA) std::forward<A ## N>(a ## N) 325 #define TEMPLATE(Z, N, DATA) \ 326 template <typename T, \ 327 ENUM_PARAMS(N, typename P), \ 328 ENUM_PARAMS(N, typename A)> \ 329 friend auto defer(const PID<T>& pid, \ 330 void (T::*method)(ENUM_PARAMS(N, P)), \ 331 ENUM_BINARY_PARAMS(N, A, &&a)) \ 332 -> _Deferred<decltype( \ 334 &std::function<void(ENUM_PARAMS(N, P))>::operator(), \ 335 std::function<void(ENUM_PARAMS(N, P))>(), \ 336 ENUM(N, FORWARD, _)))>; 341 #define TEMPLATE(Z, N, DATA) \ 342 template <typename R, \ 344 ENUM_PARAMS(N, typename P), \ 345 ENUM_PARAMS(N, typename A)> \ 346 friend auto defer(const PID<T>& pid, \ 347 Future<R> (T::*method)(ENUM_PARAMS(N, P)), \ 348 ENUM_BINARY_PARAMS(N, A, &&a)) \ 349 -> _Deferred<decltype( \ 351 &std::function<Future<R>(ENUM_PARAMS(N, P))>::operator(), \ 352 std::function<Future<R>(ENUM_PARAMS(N, P))>(), \ 353 ENUM(N, FORWARD, _)))>; 358 #define TEMPLATE(Z, N, DATA) \ 359 template <typename R, \ 361 ENUM_PARAMS(N, typename P), \ 362 ENUM_PARAMS(N, typename A)> \ 363 friend auto defer(const PID<T>& pid, \ 364 R (T::*method)(ENUM_PARAMS(N, P)), \ 365 ENUM_BINARY_PARAMS(N, A, &&a)) \ 366 -> _Deferred<decltype( \ 368 &std::function<Future<R>(ENUM_PARAMS(N, P))>::operator(), \ 369 std::function<Future<R>(ENUM_PARAMS(N, P))>(), \ 370 ENUM(N, FORWARD, _)))>; 386 #endif // __PROCESS_DEFERRED_HPP__ Definition: option.hpp:29
F && f
Definition: defer.hpp:270
friend struct _Deferred
Definition: deferred.hpp:34
internal::Partial< typename std::decay< F >::type, typename std::decay< Args >::type... > partial(F &&f, Args &&...args)
Definition: lambda.hpp:364
REPEAT_FROM_TO(1, 13, TEMPLATE, _) class AsyncExecutorProcess
Definition: async.hpp:63
Definition: type_utils.hpp:619
Definition: deferred.hpp:29
void dispatch(const PID< T > &pid, void(T::*method)())
Definition: dispatch.hpp:174
An "untyped" PID, used to encapsulate the process ID for lower-layer abstractions (eg...
Definition: pid.hpp:39
Definition: deferred.hpp:64
const T & get() const &
Definition: option.hpp:119
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:289
Definition: executor.hpp:48
Try< uint32_t > type(const std::string &path)
#define TEMPLATE(Z, N, DATA)
Definition: deferred.hpp:358
Definition: executor.hpp:29
friend Deferred< void()> defer(const PID< T > &pid, void(T::*method)())
Definition: defer.hpp:35
Definition: lambda.hpp:414