13 Asynchronous model [async]

13.26 Class template use_future_t [async.use.future]

13.26.3 Partial class template specialization async_result for use_future_t [async.use.future.result]

template<class ProtoAllocator, class Result, class... Args>
class async_result<use_future_t<ProtoAllocator>, Result(Args...)>{
  using completion_handler_type = see below;
  using return_type =  see below;

  explicit async_result(completion_handler_type& h);
  async_result(const async_result&) = delete;
  async_result& operator=(const async_result&) = delete;

  return_type get();
};

Let R be the type async_result<use_future_t<ProtoAllocator>, Result(Args...)>. Let F be the nested function object type R::completion_handler_type.

An object t1 of type F is an asynchronous provider with an associated shared state (C++ 2014 [futures.state]). The type F provides F::operator() such that the expression t1(declval<Args>()...) is well formed.

The implementation specializes associated_executor for F. For function objects executed using the associated executor's dispatch(), post() or defer() functions, any exception thrown is caught by the executor and stored in the associated shared state.

For any executor type E, the associated object for the associator associated_executor<F, E> is an executor where, for function objects executed using the executor's dispatch(), post() or defer() functions, any exception thrown by a function object is caught by the executor and stored in the associated shared state.

When an object r1 of type R is constructed from t1, the expression r1.get() returns a future with the same shared state as t1.

The type of R::return_type and the effects of F::operator() are defined in Table [tab:async.use.future.result.requirements]. After establishing these effects, F::operator() makes the shared state ready. In this table, N is the value of sizeof...(Args); let i be in the range [0, N) and let Ti be the ith type in Args; let Ui be decay_t<Ti> for each type Ti in Args; let Ai be the deduced type of the ith argument to F::operator(); and let ai be the ith argument to F::operator().

Table 10async_result<use_future_t<ProtoAllocator>, Result(Args...)> semantics
NU0R::return_typeF::operator() effects
0 future<void> None.
1 error_code future<void> If a0 evaluates to true, atomically stores the exception pointer produced by make_exception_ptr(system_error(a0)) in the shared state.
1 exception_ptr future<void> If a0 is non-null, atomically stores the exception pointer a0 in the shared state.
1 all other types future<U0> Atomically stores forward<A0>(a0) in the shared state.
2 error_code future<U1> If a0 evaluates to true, atomically stores the exception pointer produced by make_exception_ptr(system_error(a0)) in the shared state; otherwise, atomically stores forward<A1>(a1) in the shared state.
2 exception_ptr future<U1> If a0 is non-null, atomically stores the exception pointer in the shared state; otherwise, atomically stores forward<A1>(a1) in the shared state.
2 all other types future<tuple<U0, U1>> Atomically stores forward_as_tuple(
forward<A0>(a0), forward<A1>(a1))
in the shared state.
>2 error_code future<tuple<U1, , UN-1>> If a0 evaluates to true, atomically stores the exception pointer produced by make_exception_ptr(system_error(a0)) in the shared state; otherwise, atomically stores forward_as_tuple(forward<A1>(a1), , forward<AN-1>(aN-1)) in the shared state.
>2 exception_ptr future<tuple<U1, , UN-1>> If a0 is non-null, atomically stores the exception pointer in the shared state; otherwise, atomically stores forward_as_tuple(forward<A1>(a1), , forward<AN-1>(aN-1)) in the shared state.
>2 all other types future<tuple<U0, , UN-1>> Atomically stores forward_as_tuple(
forward<A0>(a0), , forward<AN-1>(aN-1))
in the shared state.