13 Asynchronous model [async]

13.3 Class template async_result [async.async.result]

The async_result class template is a customization point for asynchronous operations. Template parameter CompletionToken specifies the model used to obtain the result of the asynchronous operation. Template parameter Signature is the call signature (C++ 2014 [func.def]) for the completion handler type invoked on completion of the asynchronous operation. The async_result template:

  • transforms a CompletionToken into a completion handler type that is based on a Signature; and

  • determines the return type and return value of an asynchronous operation's initiating function.

namespace std {
namespace experimental {
namespace net {
inline namespace v1 {

  template<class CompletionToken, class Signature>
  class async_result
  {
  public:
    using completion_handler_type = CompletionToken;
    using return_type = void;

    explicit async_result(completion_handler_type&) {}
    async_result(const async_result&) = delete;
    async_result& operator=(const async_result&) = delete;

    return_type get() {}
  };

} // inline namespace v1
} // namespace net
} // namespace experimental
} // namespace std

The template parameter CompletionToken shall be an object type. The template parameter Signature shall be a call signature (C++ 2014 [func.def]).

Specializations of async_result shall satisfy the Destructible requirements (C++ 2014 [destructible]) in addition to the requirements in Table [tab:async.async.result.requirements]. In this table, R is a specialization of async_result; r is a modifiable lvalue of type R; and h is a modifiable lvalue of type R::completion_handler_type.

Table 7async_result specialization requirements
ExpressionReturn typeRequirement
R::completion_handler_type A type satisfying MoveConstructible requirements (C++ 2014 [moveconstructible]), An object of type completion_handler_type shall be a function object with call signature Signature, and completion_handler_type shall be constructible with an rvalue of type CompletionToken.
R::return_type void; or a type satisfying MoveConstructible requirements (C++ 2014 [moveconstructible])
R r(h);
r.get() R::return_type Note: An asynchronous operation's initiating function uses the get() member function as the sole operand of a return statement.  — end note ]