Documentation Home >> Headers >> <future> Header >> std::future >> std::future<>::then Member function

Schedule a function to be invoked when *this becomes ready.

template<typename Func>
future<std::result_of<Func(ResultType)>::type> then(
    Func&& func);

template<typename Func>
future<std::result_of<Func(ResultType)>::type> then(
    std::launch policy,Func&& func);


this->valid() would return true. func(this->get()) is valid. Func is MoveConstructible.


If the asynchronous result associated with *this contains a deferred function arising from a call to std::async that has not yet started execution, invokes the deferred function.

Copies func to internal storage.

If *this is ready, schedules func immediately. Otherwise, func is scheduled when the asynchronous result associated with *this becomes ready.

When func is scheduled, it is scheduled as-if std::async(policy,func,this->get()). If policy is not specified in the call to then, the policy is given the value used when creating the asynchronous result associated with *this, if any, or std::launch::deferred | std::launch::async if the asynchronous result associated with *this does not have an associated launch policy.


A new instance of std::future associated with a newly-created asynchronous result to be populated with the return value or any exception thrown by the invocation of func.


std::bad_alloc if the required internal storage cannot be allocated, otherwise std::future_error when the effects cannot be achieved, or any exception thrown during the copy of func to internal storage.


this->valid() returns false.


#include <future>

See Also