Documentation Home >> Headers >> <future> Header >> std::packaged_task class template

The std::packaged_task class template packages a function or other callable object so that when the function is invoked through the std::packaged_task instance the result is stored as an asynchronous result for retrieval through an instance of std::future.

Instances of std::packaged_task are MoveConstructible and MoveAssignable, but not CopyConstructible or CopyAssignable.

template<typename FunctionType>
class packaged_task; // undefined

template<typename ResultType,typename... ArgTypes>
class packaged_task<ResultType(ArgTypes...)>
{
public:
    typedef ResultType result_type;

    packaged_task();
    packaged_task(packaged_task&&);
    ~packaged_task();

    packaged_task& operator=(packaged_task&&);

    template<typename Callable>
    explicit packaged_task(Callable func);

    template<typename R,typename... Args>
    explicit packaged_task(R (*func)(Args...));

    template<typename Callable,typename Allocator>
    packaged_task(
        std::allocator_arg_t, const Allocator&,
        Callable);

    packaged_task(packaged_task const&) = delete;
    packaged_task& operator=(
        packaged_task const&) = delete;

    void swap(packaged_task&);

    explicit operator bool() const;

    std::future<ResultType> get_future();

    void operator()(ArgTypes...);

    void reset();
};
Header

#include <future>

See Also