13 #ifndef __PROCESS_DEFER_HPP__ 14 #define __PROCESS_DEFER_HPP__ 63 #define FORWARD_A(Z, N, DATA) std::forward<A ## N>(a ## N) 66 #define FORWARD_P(Z, N, DATA) std::forward<P ## N>(p ## N) 68 #define TEMPLATE(Z, N, DATA) \ 69 template <typename T, \ 70 ENUM_PARAMS(N, typename P), \ 71 ENUM_PARAMS(N, typename A)> \ 72 auto defer(const PID<T>& pid, \ 73 void (T::*method)(ENUM_PARAMS(N, P)), \ 74 ENUM_BINARY_PARAMS(N, A, &&a)) \ 75 -> _Deferred<decltype( \ 77 &std::function<void(ENUM_PARAMS(N, P))>::operator(), \ 78 std::function<void(ENUM_PARAMS(N, P))>(), \ 79 ENUM(N, FORWARD_A, _)))> \ 81 std::function<void(ENUM_PARAMS(N, P))> f( \ 82 [=](ENUM_BINARY_PARAMS(N, P, &&p)) { \ 83 dispatch(pid, method, ENUM(N, FORWARD_P, _)); \ 85 return lambda::partial( \ 86 &std::function<void(ENUM_PARAMS(N, P))>::operator(), \ 88 ENUM(N, FORWARD_A, _)); \ 91 template <typename T, \ 92 ENUM_PARAMS(N, typename P), \ 93 ENUM_PARAMS(N, typename A)> \ 94 auto defer(const Process<T>& process, \ 95 void (T::*method)(ENUM_PARAMS(N, P)), \ 96 ENUM_BINARY_PARAMS(N, A, &&a)) \ 97 -> decltype(defer(process.self(), method, ENUM(N, FORWARD_A, _))) \ 99 return defer(process.self(), method, ENUM(N, FORWARD_A, _)); \ 102 template <typename T, \ 103 ENUM_PARAMS(N, typename P), \ 104 ENUM_PARAMS(N, typename A)> \ 105 auto defer(const Process<T>* process, \ 106 void (T::*method)(ENUM_PARAMS(N, P)), \ 107 ENUM_BINARY_PARAMS(N, A, &&a)) \ 108 -> decltype(defer(process->self(), method, ENUM(N, FORWARD_A, _))) \ 110 return defer(process->self(), method, ENUM(N, FORWARD_A, _)); \ 119 template <
typename R,
typename T>
125 template <
typename R,
typename T>
131 template <
typename R,
typename T>
137 #define TEMPLATE(Z, N, DATA) \ 138 template <typename R, \ 140 ENUM_PARAMS(N, typename P), \ 141 ENUM_PARAMS(N, typename A)> \ 142 auto defer(const PID<T>& pid, \ 143 Future<R> (T::*method)(ENUM_PARAMS(N, P)), \ 144 ENUM_BINARY_PARAMS(N, A, &&a)) \ 145 -> _Deferred<decltype( \ 147 &std::function<Future<R>(ENUM_PARAMS(N, P))>::operator(), \ 148 std::function<Future<R>(ENUM_PARAMS(N, P))>(), \ 149 ENUM(N, FORWARD_A, _)))> \ 151 std::function<Future<R>(ENUM_PARAMS(N, P))> f( \ 152 [=](ENUM_BINARY_PARAMS(N, P, &&p)) { \ 153 return dispatch(pid, method, ENUM(N, FORWARD_P, _)); \ 155 return lambda::partial( \ 156 &std::function<Future<R>(ENUM_PARAMS(N, P))>::operator(), \ 158 ENUM(N, FORWARD_A, _)); \ 161 template <typename R, \ 163 ENUM_PARAMS(N, typename P), \ 164 ENUM_PARAMS(N, typename A)> \ 165 auto defer(const Process<T>& process, \ 166 Future<R> (T::*method)(ENUM_PARAMS(N, P)), \ 167 ENUM_BINARY_PARAMS(N, A, &&a)) \ 168 -> decltype(defer(process.self(), method, ENUM(N, FORWARD_A, _))) \ 170 return defer(process.self(), method, ENUM(N, FORWARD_A, _)); \ 173 template <typename R, \ 175 ENUM_PARAMS(N, typename P), \ 176 ENUM_PARAMS(N, typename A)> \ 177 auto defer(const Process<T>* process, \ 178 Future<R> (T::*method)(ENUM_PARAMS(N, P)), \ 179 ENUM_BINARY_PARAMS(N, A, &&a)) \ 180 -> decltype(defer(process->self(), method, ENUM(N, FORWARD_A, _))) \ 182 return defer(process->self(), method, ENUM(N, FORWARD_A, _)); \ 191 template <
typename R,
typename T>
197 template <
typename R,
typename T>
203 template <
typename R,
typename T>
209 #define TEMPLATE(Z, N, DATA) \ 210 template <typename R, \ 212 ENUM_PARAMS(N, typename P), \ 213 ENUM_PARAMS(N, typename A)> \ 214 auto defer(const PID<T>& pid, \ 215 R (T::*method)(ENUM_PARAMS(N, P)), \ 216 ENUM_BINARY_PARAMS(N, A, &&a)) \ 217 -> _Deferred<decltype( \ 219 &std::function<Future<R>(ENUM_PARAMS(N, P))>::operator(), \ 220 std::function<Future<R>(ENUM_PARAMS(N, P))>(), \ 221 ENUM(N, FORWARD_A, _)))> \ 223 std::function<Future<R>(ENUM_PARAMS(N, P))> f( \ 224 [=](ENUM_BINARY_PARAMS(N, P, &&p)) { \ 225 return dispatch(pid, method, ENUM(N, FORWARD_P, _)); \ 227 return lambda::partial( \ 228 &std::function<Future<R>(ENUM_PARAMS(N, P))>::operator(), \ 230 ENUM(N, FORWARD_A, _)); \ 233 template <typename R, \ 235 ENUM_PARAMS(N, typename P), \ 236 ENUM_PARAMS(N, typename A)> \ 238 defer(const Process<T>& process, \ 239 R (T::*method)(ENUM_PARAMS(N, P)), \ 240 ENUM_BINARY_PARAMS(N, A, &&a)) \ 241 -> decltype(defer(process.self(), method, ENUM(N, FORWARD_A, _))) \ 243 return defer(process.self(), method, ENUM(N, FORWARD_A, _)); \ 246 template <typename R, \ 248 ENUM_PARAMS(N, typename P), \ 249 ENUM_PARAMS(N, typename A)> \ 251 defer(const Process<T>* process, \ 252 R (T::*method)(ENUM_PARAMS(N, P)), \ 253 ENUM_BINARY_PARAMS(N, A, &&a)) \ 254 -> decltype(defer(process->self(), method, ENUM(N, FORWARD_A, _))) \ 256 return defer(process->self(), method, ENUM(N, FORWARD_A, _)); \ 268 template <
typename F>
269 _Deferred<F>
defer(
const UPID& pid, F&&
f)
275 template <
typename F>
287 #endif // __PROCESS_DEFER_HPP__ F && f
Definition: defer.hpp:270
REPEAT_FROM_TO(1, 13, TEMPLATE, _) class AsyncExecutorProcess
Definition: async.hpp:63
Definition: deferred.hpp:29
void dispatch(const PID< T > &pid, void(T::*method)())
Definition: dispatch.hpp:174
thread_local ProcessBase * __process__
Definition: deferred.hpp:64
#define TEMPLATE(Z, N, DATA)
Definition: defer.hpp:209
A "process identifier" used to uniquely identify a process when dispatching messages.
Definition: pid.hpp:289
Definition: executor.hpp:48
PID< T > self() const
Returns the PID of the process.
Definition: process.hpp:514
#define __executor__
Definition: executor.hpp:108
Definition: process.hpp:505
Deferred< void()> defer(const PID< T > &pid, void(T::*method)())
Definition: defer.hpp:35
const UPID & self() const
Definition: process.hpp:79