diff --git a/listings/listing_4.14.cpp b/listings/listing_4.14.cpp index 424b7e8..0624b04 100644 --- a/listings/listing_4.14.cpp +++ b/listings/listing_4.14.cpp @@ -1,13 +1,15 @@ #include -template -std::future::type> -spawn_task(F&& f,A&& a) -{ - typedef std::result_of::type result_type; - std::packaged_task - task(std::move(f)); - std::future res(task.get_future()); - std::thread t(std::move(task),std::move(a)); - t.detach(); - return res; + +template +std::future> spawn_task(Func &&f, Args &&...rest) { + typedef std::invoke_result_t result_type; + + std::packaged_task task(std::move(f)); + + std::future result(task.get_future()); + + std::thread worker(std::move(task), std::move(rest)...); + worker.detach(); + + return result; }