Documentation Home >> Headers >> <jss/experimental_future.hpp> Header >> std::experimental::future >> std::experimental::future<>::then Member function

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

template<typename Func>
see below then(
    Func&& func);

template<typename Func>
see below 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 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.


If std::result_of<Func(ResultType)>::type is an instance of either std::experimental::future or std::experimental::shared_future, then returns std::result_of<Func(ResultType)>::type; the resulting future will become ready when the continuation function has completed, and the future returned from the continuation is ready, as per the std::experimental::future Unwrapping constructor.

Otherwise, returns a new instance of std::experimental::future<std::result_of<Func(ResultType)>::type> 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 <experimental/future>

See Also