Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / asio / use_awaitable.hpp
index 8764b3d..fa5eddd 100644 (file)
@@ -46,9 +46,47 @@ namespace asio {
 template <typename Executor = executor>
 struct use_awaitable_t
 {
+  /// Default constructor.
   BOOST_ASIO_CONSTEXPR use_awaitable_t()
   {
   }
+
+  /// Adapts an executor to add the @c use_awaitable_t completion token as the
+  /// default.
+  template <typename InnerExecutor>
+  struct executor_with_default : InnerExecutor
+  {
+    /// Specify @c use_awaitable_t as the default completion token type.
+    typedef use_awaitable_t default_completion_token_type;
+
+    /// Construct the adapted executor from the inner executor type.
+    executor_with_default(const InnerExecutor& ex) BOOST_ASIO_NOEXCEPT
+      : InnerExecutor(ex)
+    {
+    }
+  };
+
+  /// Type alias to adapt an I/O object to use @c use_awaitable_t as its
+  /// default completion token type.
+#if defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES) \
+  || defined(GENERATING_DOCUMENTATION)
+  template <typename T>
+  using as_default_on_t = typename T::template rebind_executor<
+      executor_with_default<typename T::executor_type> >::other;
+#endif // defined(BOOST_ASIO_HAS_ALIAS_TEMPLATES)
+       //   || defined(GENERATING_DOCUMENTATION)
+
+  /// Function helper to adapt an I/O object to use @c use_awaitable_t as its
+  /// default completion token type.
+  template <typename T>
+  static typename T::template rebind_executor<
+      executor_with_default<typename T::executor_type>
+    >::other
+  as_default_on(BOOST_ASIO_MOVE_ARG(T) object)
+  {
+    return typename as_default_on_t<typename decay<T>::type>::type(
+        BOOST_ASIO_MOVE_CAST(T)(object));
+  }
 };
 
 /// A completion token object that represents the currently executing coroutine.