| Taskflow: A General-purpose Task-parallel Programming System

Loading...
Searching...
No Matches
tf::StaticTaskLike Concept Reference

concept to check if a callable is a static task More...

`#include <taskflow/core/task.hpp>`

## Concept definition

template<typename C>
concept tf::StaticTaskLike = std::invocable<C> &&
std::same_as<std::invoke_result_t<C>, void>
tf::StaticTaskLike
concept to check if a callable is a static task
Definition task.hpp:140

## Detailed Description

concept to check if a callable is a static task

A static task is a callable object that takes no arguments and returns void. It is constructible from std::function<void()>.

Requirements
  - Must be invocable with no arguments
  - Must return void

Examples

// Valid static tasks (satisfy StaticTaskLike)
// Simple lambda capturing nothing
auto static_task1 = []() {};
static_assert(StaticTaskLike<decltype(static_task1)>);
// Lambda capturing variables
int x = 10;
auto static_task2 = [x]() { std::cout << x << '\n'; };
static_assert(StaticTaskLike<decltype(static_task2)>);
// Function object (functor)
struct SimpleTask {
void operator()() const { std::cout << "task\n"; }
};
static_assert(StaticTaskLike<SimpleTask>);
// Free function
void my_task() { std::cout << "free function task\n"; }
static_assert(StaticTaskLike<decltype(&my_task)>);
// Use in taskflow
tf::Taskflow taskflow;
auto task = taskflow.emplace(static_task1).name("static");
tf::FlowBuilder::emplace
Task emplace(C &&callable)
creates a static task
Definition flow_builder.hpp:1738
tf::Task::name
const std::string & name() const
queries the name of the task
Definition task.hpp:1435
tf::Taskflow
class to create a taskflow object
Definition taskflow.hpp:64

Invalid Examples

// Invalid: takes parameters
auto task_with_param = [](int a) { std::cout << a << '\n'; };
// static_assert(StaticTaskLike<decltype(task_with_param)>); // FAILS
// Invalid: returns non-void
auto task_returns_int = []() { return 42; };
// static_assert(StaticTaskLike<decltype(task_returns_int)>); // FAILS