拆分出bind方法

This commit is contained in:
2024-01-23 16:55:26 +08:00
parent ca23184273
commit 782e17f05a

View File

@@ -47,9 +47,12 @@ namespace ling {
public:
template<typename F, typename... Args>
explicit Timer(F &&f, Args &&...args) {
explicit Timer() {
this->id = nextId++;
}
template<typename F, typename... Args>
Timer &bind(F &&f, Args &&...args) {
std::function<decltype(f(args...))()> func = std::bind(std::forward<F>(f), std::forward<Args>(
args)...); // 连接函数和参数定义,特殊函数类型,避免左右值错误
auto task_ptr = std::make_shared<std::packaged_task<decltype(f(args...))()>>(func);
@@ -69,6 +72,7 @@ namespace ling {
};
task.fun = warpper_func;
task.id = this->id;
return *this;
}