std::packaged_task<> is a class template introduced with the C++11 multi-threading functionality. This tag should be used for questions concerning the C++ class template and using it with C++ multi-threading and coroutines. The C++ Standard being used (C++11/14/17/20) should also be indicated. The class template is used to wrap a callable entity (lambda, function, etc.) to create an asynchronous task.
std::packaged_task<>
is a class template introduced with the C++11 Standard that is part of the multi-threading functionality introduced with that version of the Standard. It requires the use of #include <future>
to compile.
The purpose of std::packaged_task<>
is to create an asynchronous task which can then be used with other C++ multi-threading library functionality to manage. You can use a std::future<>
to get the result of the asynchronous task.
You can also use std::packaged_task<>
along with its get_future()
method with the proposed co_await
operator of C++20 coroutines.
To use std::packaged_task<>
requires two steps: create the packaged task object and call the object to start it running.
Additional reading
What is the difference between packaged_task and async