I was naively expecting this to compile:
template <typename Func>
auto run(Func && func) {
auto package = std::packaged_task{std::forward<Func>(func)}; // deduce the template args automatically (C++17)
auto future = package.get_future();
enqueue(std::packaged_task<void()>{std::move(package)}); // only works if packaged_task is <R()>, but ok
return future;
}
For exposition: this might be from a thread-pool implementation, enqueue()
just queues the argument for execution on the worker threads.
The thing is, however, that there are no deduction guides for packaged_task
, so C++17 constructor template argument deduction fails, of course.
So, why are there no deduction guides?