From a572967eea3c6a2c064883a4b7d6c06945266020 Mon Sep 17 00:00:00 2001 From: ITHelpDec <34002836+ITHelpDec@users.noreply.github.com> Date: Sun, 23 Apr 2023 22:35:55 +0300 Subject: [PATCH] `std::result_of` deprecation See [here](https://en.cppreference.com/w/cpp/types/result_of#Notes) for reasons why `std::invoke_result_t` is to be used over `std::result_of<>::type`. Code also amended functionally to make the template variadic (whitespace and naming amendments preferential and optional). At the very least, lines 3 and 6 need to be amended to include `typename` in order to compile. .:. Line 3 .:. std::future::type> std::future::type> .:. Line 6 .:. typedef std::result_of::type result_type; typedef typename std::result_of::type result_type; --- listings/listing_4.14.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) 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; }