Created
January 24, 2020 12:45
-
-
Save amigo421/5c516c8d6c5c8b14d5e7b2399a053e2b to your computer and use it in GitHub Desktop.
SpawnTask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename function_type, typename... argument_types> | |
auto spawn_task(function_type &&f, argument_types &&... args) { | |
using result_type = | |
typename std::result_of<function_type(argument_types && ...)>::type; | |
using packaged_task = std::packaged_task<result_type(argument_types && ...)>; | |
auto task = packaged_task{std::forward<function_type>(f)}; | |
auto future = task.get_future(); | |
task(args...); | |
return future; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment