packaged_task() noexcept;
template <class F>
packaged_task(F&& f);
Requires: INVOKE<R>(f, t1, t2, ..., tN), where t1, t2, ..., tN are values of the corresponding types in ArgTypes..., shall be a valid expression. Invoking a copy of f shall behave the same as invoking f.
Remarks: This constructor shall not participate in overload resolution if decay_t<F> is the same type as packaged_task<R(ArgTypes...)>.
Effects: Constructs a new packaged_task object with a shared state and initializes the object's stored task with std::forward<F>(f).
Throws:
Any exceptions thrown by the copy or move constructor of f.
For the first version, bad_alloc if memory for the internal data structures could not be allocated.
For the second version, any exceptions thrown by allocator_traits<Allocator>::template rebind_traits<unspecified>::allocate.
packaged_task(packaged_task&& rhs) noexcept;
Effects: Constructs a new packaged_task object and transfers ownership of rhs's shared state to *this, leaving rhs with no shared state. Moves the stored task from rhs to *this.
packaged_task& operator=(packaged_task&& rhs) noexcept;
Effects:
Releases any shared state ([futures.state]);
calls packaged_task(std::move(rhs)).swap(*this).
~packaged_task();
Effects: Abandons any shared state ([futures.state]).
void swap(packaged_task& other) noexcept;
Postconditions: *this has the same shared state and stored task (if any) as other prior to the call to swap. other has the same shared state and stored task (if any) as *this prior to the call to swap.
bool valid() const noexcept;
future<R> get_future();
void operator()(ArgTypes... args);
Effects: As if by INVOKE<R>(f, t1, t2, ..., tN), where f is the stored task of *this and t1, t2, ..., tN are the values in args.... If the task returns normally, the return value is stored as the asynchronous result in the shared state of *this, otherwise the exception thrown by the task is stored. The shared state of *this is made ready, and any threads blocked in a function waiting for the shared state of *this to become ready are unblocked.
Throws: a future_error exception object if there is no shared state or the stored task has already been invoked.
void make_ready_at_thread_exit(ArgTypes... args);
Effects: As if by INVOKE<R>(f, t1, t2, ..., tN), where f is the stored task and t1, t2, ..., tN are the values in args.... If the task returns normally, the return value is stored as the asynchronous result in the shared state of *this, otherwise the exception thrown by the task is stored. In either case, this shall be done without making that state ready ([futures.state]) immediately. Schedules the shared state to be made ready when the current thread exits, after all objects of thread storage duration associated with the current thread have been destroyed.
void reset();
Effects: As if *this = packaged_task(std::move(f)), where f is the task stored in *this. [ Note: This constructs a new shared state for *this. The old state is abandoned ([futures.state]). — end note ]