Documentation Home >> Headers >> <future> Header >> std::packaged_task >> std::packaged_task Construction from a Callable object

Construct a std::packaged_task object with an associated task and asynchronous result.

template<typename Callable>
packaged_task(Callable func);


The expression func(args...) shall be valid, where each element args-i in args... shall be a value of the corresponding type ArgTypes-i in ArgTypes.... The return value shall be convertible to ResultType.


Constructs a std::packaged_task instance with an associated asynchronous result of type ResultType that is not ready and an associated task of type Callable that is a copy of func.


An exception of type std::bad_alloc if the constructor is unable to allocate memory for the asynchronous result. Any exception thrown by the copy or move constructor of Callable.


#include <future>

See Also