拆分出bind方法
This commit is contained in:
@@ -47,9 +47,12 @@ namespace ling {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
template<typename F, typename... Args>
|
explicit Timer() {
|
||||||
explicit Timer(F &&f, Args &&...args) {
|
|
||||||
this->id = nextId++;
|
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>(
|
std::function<decltype(f(args...))()> func = std::bind(std::forward<F>(f), std::forward<Args>(
|
||||||
args)...); // 连接函数和参数定义,特殊函数类型,避免左右值错误
|
args)...); // 连接函数和参数定义,特殊函数类型,避免左右值错误
|
||||||
auto task_ptr = std::make_shared<std::packaged_task<decltype(f(args...))()>>(func);
|
auto task_ptr = std::make_shared<std::packaged_task<decltype(f(args...))()>>(func);
|
||||||
@@ -69,6 +72,7 @@ namespace ling {
|
|||||||
};
|
};
|
||||||
task.fun = warpper_func;
|
task.fun = warpper_func;
|
||||||
task.id = this->id;
|
task.id = this->id;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user