pass task functor by copy to avoid dangling pointers

This commit is contained in:
Francisco Paisana 2019-11-22 15:29:03 +00:00
parent b2d3c2a150
commit 6746c5dfa5
1 changed files with 3 additions and 3 deletions

View File

@ -240,10 +240,10 @@ public:
{ {
} }
template <typename Func> template <typename Func>
moveable_task_t(Func&& f, Capture&& c) : moveable_task_t(Func&& f, Capture&& c) : capture(std::forward<Capture>(c))
func([this, f]() { f(std::move(capture)); }),
capture(std::forward<Capture>(c))
{ {
std::function<void(Capture)> ftmp{std::forward<Func>(f)};
func = [this, ftmp]() { ftmp(std::move(capture)); };
} }
void operator()() { func(); } void operator()() { func(); }