cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
task_base.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
6{
7// Abstract base class for type erasure
9{
10 virtual ~task_base() = default;
11 virtual void execute() = 0; // Pure virtual function to execute the task
12};
13
14// Template derived class to hold the actual callable object
15template<typename F>
17{
18 F func; // The callable object (lambda, function, etc.)
19
20 // Constructor moves the callable object into the 'func' member
21 explicit task_derived(F&& f)
22 : func(std::move(f))
23 {
24 }
25
26 // Override execute to call the stored callable
27 void execute() override { func(); }
28};
29} // namespace toolbox::base::detail
Definition object_pool.hpp:100
Definition task_base.hpp:6
Definition task_base.hpp:9
Definition task_base.hpp:17
task_derived(F &&f)
Definition task_base.hpp:21
void execute() override
Definition task_base.hpp:27
F func
Definition task_base.hpp:18