17 constexpr
bool is_static_task_v = is_invocable_r_v<void, C> &&
18 !is_invocable_r_v<int, C>;
26 constexpr
bool is_dynamic_task_v = is_invocable_r_v<void, C, Subflow&>;
34 constexpr
bool is_condition_task_v = is_invocable_r_v<int, C>;
132 template <
typename C>
133 std::enable_if_t<is_static_task_v<C>,
Task>&
work(C&& callable);
144 template <
typename C>
145 std::enable_if_t<is_dynamic_task_v<C>,
Task>&
work(C&& callable);
156 template <
typename C>
157 std::enable_if_t<is_condition_task_v<C>,
Task>&
work(C&& callable);
177 template <
typename... Ts>
189 template <
typename... Ts>
215 template <
typename V>
221 template <
typename V>
228 Node* _node {
nullptr};
230 template <
typename T>
233 template <
typename T,
typename... Rest>
234 void _precede(T&&, Rest&&...);
236 template <
typename T>
239 template <
typename T,
typename... Rest>
240 void _succeed(T&&, Rest&&...);
244 inline Task::Task(Node* node) : _node {node} {
252 template <
typename... Ts>
255 _precede(std::forward<Ts>(tasks)...);
260 template <
typename T>
261 void Task::_precede(T&& other) {
262 _node->_precede(other._node);
266 template <
typename T,
typename... Ts>
267 void Task::_precede(T&& task, Ts&&... others) {
268 _precede(std::forward<T>(task));
269 _precede(std::forward<Ts>(others)...);
273 template <
typename... Ts>
276 _succeed(std::forward<Ts>(tasks)...);
281 template <
typename T>
282 void Task::_succeed(T&& other) {
283 other._node->_precede(_node);
287 template <
typename T,
typename... Ts>
288 void Task::_succeed(T&& task, Ts&&... others) {
289 _succeed(std::forward<T>(task));
290 _succeed(std::forward<Ts>(others)...);
295 _node->_handle.emplace<Node::ModuleWork>(&tf);
313 return _node == rhs._node;
318 return _node != rhs._node;
334 _node->_handle = nstd::monostate{};
344 return _node->num_dependents();
349 return _node->num_strong_dependents();
354 return _node->num_weak_dependents();
359 return _node->num_successors();
364 return _node ==
nullptr;
369 return _node ? _node->_handle.index() != 0 :
false;
373 template <
typename V>
375 for(
size_t i=0; i<_node->_successors.size(); ++i) {
376 visitor(
Task(_node->_successors[i]));
381 template <
typename V>
383 for(
size_t i=0; i<_node->_dependents.size(); ++i) {
384 visitor(
Task(_node->_dependents[i]));
480 template <
typename V>
486 template <
typename V>
493 Node* _node {
nullptr};
533 return _node->num_dependents();
538 return _node->num_strong_dependents();
543 return _node->num_weak_dependents();
548 return _node->num_successors();
558 return _node ==
nullptr;
563 return _node == rhs._node;
568 return _node != rhs._node;
572 template <
typename V>
574 for(
size_t i=0; i<_node->_successors.size(); ++i) {
575 visitor(
TaskView(_node->_successors[i]));
580 template <
typename V>
582 for(
size_t i=0; i<_node->_dependents.size(); ++i) {
583 visitor(
TaskView(_node->_dependents[i]));
size_t num_dependents() const
queries the number of predecessors of the task
Definition: task.hpp:343
void reset_work()
resets the associated work to a placeholder
Definition: task.hpp:333
void reset()
resets the task handle to null
Definition: task.hpp:328
TaskView()=default
constructs an empty task view
bool operator!=(const TaskView &) const
compares if two taskviews are associated with different tasks
Definition: task.hpp:567
void for_each_dependent(V &&visitor) const
applies an visitor callable to each dependents of the task
Definition: task.hpp:581
size_t num_weak_dependents() const
queries the number of weak dependents of the task
Definition: task.hpp:542
size_t num_successors() const
queries the number of successors of the task
Definition: task.hpp:547
Definition: taskflow.hpp:5
bool operator==(const Task &rhs) const
compares if two tasks are associated with the same graph node
Definition: task.hpp:312
std::enable_if_t< is_static_task_v< C >, Task > & work(C &&callable)
assigns a static task
Definition: flow_builder.hpp:943
Task & succeed(Ts &&... tasks)
adds precedence links from other tasks to this
Definition: task.hpp:274
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition: task.hpp:573
bool operator!=(const Task &rhs) const
compares if two tasks are not associated with the same graph node
Definition: task.hpp:317
bool empty() const
queries if the task view is empty
Definition: task.hpp:557
size_t num_strong_dependents() const
queries the number of strong dependents of the task
Definition: task.hpp:537
Task & operator=(const Task &)
replaces the contents with a copy of the other task
Definition: task.hpp:300
void for_each_dependent(V &&visitor) const
applies an visitor callable to each dependents of the task
Definition: task.hpp:382
the class to create a task dependency graph
Definition: core/taskflow.hpp:18
const std::string & name() const
queries the name of the task
Definition: task.hpp:338
an immutable accessor class to a task node, mainly used in the tf::ExecutorObserver interface...
Definition: task.hpp:396
bool empty() const
queries if the task handle points to a task node
Definition: task.hpp:363
void reset()
resets to an empty view
Definition: task.hpp:552
size_t num_strong_dependents() const
queries the number of strong dependents of the task
Definition: task.hpp:348
Building blocks of a task dependency graph.
Definition: flow_builder.hpp:13
size_t num_successors() const
queries the number of successors of the task
Definition: task.hpp:358
size_t num_weak_dependents() const
queries the number of weak dependents of the task
Definition: task.hpp:353
task handle to a node in a task dependency graph
Definition: task.hpp:51
Task & precede(Ts &&... tasks)
adds precedence links from this to other tasks
Definition: task.hpp:253
void for_each_successor(V &&visitor) const
applies an visitor callable to each successor of the task
Definition: task.hpp:374
Task()=default
constructs an empty task
The executor class to run a taskflow graph.
Definition: executor.hpp:33
TaskView & operator=(const TaskView &other)
replaces the contents with a copy of the other task
Definition: task.hpp:509
bool operator==(const TaskView &) const
compares if two taskviews are associated with the same task
Definition: task.hpp:562
size_t num_dependents() const
queries the number of predecessors of the task
Definition: task.hpp:532
bool has_work() const
queries if the task has a work assigned
Definition: task.hpp:368
const std::string & name() const
queries the name of the task
Definition: task.hpp:527
Task & composed_of(Taskflow &)
creates a module task from a taskflow
Definition: task.hpp:294