54#if !defined(PTL_DEFAULT_OBJECT)
55# define PTL_DEFAULT_OBJECT(NAME) \
58 NAME(const NAME&) = default; \
59 NAME(NAME&&) noexcept = default; \
60 NAME& operator=(const NAME&) = default; \
61 NAME& operator=(NAME&&) noexcept = default;
66template <
typename JoinT,
typename JoinArg>
70 using Type = std::function<JoinT(JoinT&, JoinArg&&)>;
75 template <
typename Func>
77 : m_func(std::forward<Func>(func))
80 template <
typename... Args>
83 return std::move(m_func(std::forward<Args>(args)...));
87 Type m_func = [](JoinT& lhs, JoinArg&&) {
return lhs; };
92template <
typename JoinArg>
96 using Type = std::function<void(JoinArg)>;
101 template <
typename Func>
103 : m_func(std::forward<Func>(func))
106 template <
typename... Args>
109 m_func(std::forward<Args>(args)...);
113 Type m_func = [](JoinArg) {};
122 using Type = std::function<void()>;
127 template <
typename Func>
129 : m_func(std::forward<Func>(func))
135 Type m_func = []() {};
140template <
typename Tp,
typename Arg = Tp>
160 template <
typename... Args>
166 template <
typename Func>
169 ,
m_join(std::forward<Func>(_join))
171 template <typename Up = Tp, enable_if_t<std::is_same<Up, void>::value,
int> = 0>
190 template <
typename Up>
198 m_task_set.push_back(std::move(_task->get_future()));
205 template <
typename Func,
typename... Args>
214 template <
typename Func,
typename... Args>
215 void exec(Func&& func, Args... args)
220 template <
typename Func,
typename... Args>
221 void run(Func&& func, Args... args)
226 template <
typename Func,
typename... Args>
227 void parallel_for(
const intmax_t& nitr,
const intmax_t& chunks, Func&& func,
230 auto nsplit = nitr / chunks;
231 auto nmod = nitr % chunks;
234 for(intmax_t n = 0; n < nsplit; ++n)
236 auto _beg = n * chunks;
237 auto _end = (n + 1) * chunks + ((n + 1 == nsplit) ? nmod : 0);
238 run(std::forward<Func>(func), std::move(_beg), std::move(_end), args...);
273 template <typename Up = Tp, enable_if_t<!std::is_void<Up>::value,
int> = 0>
279 using RetT =
decay_t<
decltype(itr.get())>;
280 accum = std::move(
m_join(std::ref(accum), std::forward<RetT>(itr.get())));
287 template <
typename Up = Tp,
typename Rp = Arg,
288 enable_if_t<std::is_void<Up>::value && std::is_void<Rp>::value,
int> = 0>
299 template <
typename Up = Tp,
typename Rp = Arg,
306 using RetT =
decay_t<
decltype(itr.get())>;
307 m_join(std::forward<RetT>(itr.get()));
#define PTL_DEFAULT_OBJECT(NAME)
TaskGroup(ThreadPool *_tp=nullptr)
task_type< Args... > * wrap(Func &&func, Args... args)
TaskGroup(Func &&_join, ThreadPool *_tp=nullptr)
const_reverse_iterator critr_t
this_type & operator=(this_type &&rhs)=default
std::future< ArgTp > future_type
task_list_t::const_reverse_iterator const_reverse_iterator
void exec(Func &&func, Args... args)
std::promise< ArgTp > promise_type
std::packaged_task< ArgTp()> packaged_task_type
TaskGroup(const this_type &)=delete
task_list_t & get_tasks()
JoinFunction< Tp, Arg >::Type join_type
Up * operator+=(Up *_task)
const task_list_t & get_tasks() const
this_type & operator=(const this_type &rhs)=delete
void parallel_for(const intmax_t &nitr, const intmax_t &chunks, Func &&func, Args... args)
task_list_t::const_iterator const_iterator
task_list_t::iterator iterator
void run(Func &&func, Args... args)
list_type< future_type > task_list_t
TaskGroup(this_type &&rhs)=default
TaskGroup< Tp, Arg > this_type
task_list_t::reverse_iterator reverse_iterator
The task class is supplied to thread_pool.
size_type add_task(task_pointer task, int bin=-1)
vtask_list_type vtask_list
std::vector< Tp > list_type
typename std::decay< T >::type decay_t
typename std::enable_if< B, T >::type enable_if_t
JoinFunction(Func &&func)
std::function< void(JoinArg)> Type
void operator()(Args &&... args)
std::function< void()> Type
JoinFunction(Func &&func)
JoinT & operator()(Args &&... args)
JoinFunction(Func &&func)
std::function< JoinT(JoinT &, JoinArg &&)> Type