Documentation Home >> Headers >> <future> Header >> std::packaged_task >> std::packaged_task::operator() Function Call Operator

Invoke the task associated with a std::packaged_task instance, and store the return value or exception in the associated asynchronous result.

void operator()(ArgTypes... args);

Preconditions:

*this has an associated task.

Effects:

Invoke the associated task func as-if INVOKE(func,args...). If the invocation returns normally, store the return value in the asynchronous result associated with *this. If the invocation returns with an exception, store the exception in the asynchronous result associated with *this.

Postconditions:

The asynchronous result associated with *this is ready with a stored value or exception. Any threads blocked waiting for the asynchronous result are unblocked.

Throws:

An exception of type std::future_error with an error code of std::future_errc::promise_already_satisfied if the asynchronous result is already ready..

Synchronization:

A successful call to the function call operator happens-before a call to std::future<ResultType>::get() or std::shared_future<ResultType>::get() which retrieves the value or exception stored.

Header

#include <future>

See Also