Skip to content

Instantly share code, notes, and snippets.

@amigo421
Created January 24, 2020 12:45
Show Gist options
  • Save amigo421/5c516c8d6c5c8b14d5e7b2399a053e2b to your computer and use it in GitHub Desktop.
Save amigo421/5c516c8d6c5c8b14d5e7b2399a053e2b to your computer and use it in GitHub Desktop.
SpawnTask
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