Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / asio / impl / compose.hpp
index 76fe54d..2dfc4bb 100644 (file)
@@ -33,59 +33,50 @@ namespace asio {
 namespace detail
 {
   template <typename>
-  struct composed_work;
+  struct composed_io_executors;
 
   template <>
-  struct composed_work<void()>
+  struct composed_io_executors<void()>
   {
-    composed_work() BOOST_ASIO_NOEXCEPT
+    composed_io_executors() BOOST_ASIO_NOEXCEPT
       : head_(system_executor())
     {
     }
 
-    void reset()
-    {
-      head_.reset();
-    }
-
     typedef system_executor head_type;
-    executor_work_guard<system_executor> head_;
+    system_executor head_;
   };
 
-  inline composed_work<void()> make_composed_work()
+  inline composed_io_executors<void()> make_composed_io_executors()
   {
-    return composed_work<void()>();
+    return composed_io_executors<void()>();
   }
 
   template <typename Head>
-  struct composed_work<void(Head)>
+  struct composed_io_executors<void(Head)>
   {
-    explicit composed_work(const Head& ex) BOOST_ASIO_NOEXCEPT
+    explicit composed_io_executors(const Head& ex) BOOST_ASIO_NOEXCEPT
       : head_(ex)
     {
     }
 
-    void reset()
-    {
-      head_.reset();
-    }
-
     typedef Head head_type;
-    executor_work_guard<Head> head_;
+    Head head_;
   };
 
   template <typename Head>
-  inline composed_work<void(Head)> make_composed_work(const Head& head)
+  inline composed_io_executors<void(Head)>
+  make_composed_io_executors(const Head& head)
   {
-    return composed_work<void(Head)>(head);
+    return composed_io_executors<void(Head)>(head);
   }
 
 #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
 
   template <typename Head, typename... Tail>
-  struct composed_work<void(Head, Tail...)>
+  struct composed_io_executors<void(Head, Tail...)>
   {
-    explicit composed_work(const Head& head,
+    explicit composed_io_executors(const Head& head,
         const Tail&... tail) BOOST_ASIO_NOEXCEPT
       : head_(head),
         tail_(tail...)
@@ -99,24 +90,24 @@ namespace detail
     }
 
     typedef Head head_type;
-    executor_work_guard<Head> head_;
-    composed_work<void(Tail...)> tail_;
+    Head head_;
+    composed_io_executors<void(Tail...)> tail_;
   };
 
   template <typename Head, typename... Tail>
-  inline composed_work<void(Head, Tail...)>
-  make_composed_work(const Head& head, const Tail&... tail)
+  inline composed_io_executors<void(Head, Tail...)>
+  make_composed_io_executors(const Head& head, const Tail&... tail)
   {
-    return composed_work<void(Head, Tail...)>(head, tail...);
+    return composed_io_executors<void(Head, Tail...)>(head, tail...);
   }
 
 #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
 
-#define BOOST_ASIO_PRIVATE_COMPOSED_WORK_DEF(n) \
+#define BOOST_ASIO_PRIVATE_COMPOSED_IO_EXECUTORS_DEF(n) \
   template <typename Head, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
-  struct composed_work<void(Head, BOOST_ASIO_VARIADIC_TARGS(n))> \
+  struct composed_io_executors<void(Head, BOOST_ASIO_VARIADIC_TARGS(n))> \
   { \
-    explicit composed_work(const Head& head, \
+    explicit composed_io_executors(const Head& head, \
         BOOST_ASIO_VARIADIC_CONSTREF_PARAMS(n)) BOOST_ASIO_NOEXCEPT \
       : head_(head), \
         tail_(BOOST_ASIO_VARIADIC_BYVAL_ARGS(n)) \
@@ -130,19 +121,116 @@ namespace detail
     } \
   \
     typedef Head head_type; \
-    executor_work_guard<Head> head_; \
-    composed_work<void(BOOST_ASIO_VARIADIC_TARGS(n))> tail_; \
+    Head head_; \
+    composed_io_executors<void(BOOST_ASIO_VARIADIC_TARGS(n))> tail_; \
   }; \
   \
   template <typename Head, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
-  inline composed_work<void(Head, BOOST_ASIO_VARIADIC_TARGS(n))> \
-  make_composed_work(const Head& head, BOOST_ASIO_VARIADIC_CONSTREF_PARAMS(n)) \
+  inline composed_io_executors<void(Head, BOOST_ASIO_VARIADIC_TARGS(n))> \
+  make_composed_io_executors(const Head& head, \
+      BOOST_ASIO_VARIADIC_CONSTREF_PARAMS(n)) \
   { \
-    return composed_work< \
+    return composed_io_executors< \
       void(Head, BOOST_ASIO_VARIADIC_TARGS(n))>( \
         head, BOOST_ASIO_VARIADIC_BYVAL_ARGS(n)); \
   } \
   /**/
+  BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_COMPOSED_IO_EXECUTORS_DEF)
+#undef BOOST_ASIO_PRIVATE_COMPOSED_IO_EXECUTORS_DEF
+
+#endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
+
+  template <typename>
+  struct composed_work;
+
+  template <>
+  struct composed_work<void()>
+  {
+    typedef composed_io_executors<void()> executors_type;
+
+    composed_work(const executors_type&) BOOST_ASIO_NOEXCEPT
+      : head_(system_executor())
+    {
+    }
+
+    void reset()
+    {
+      head_.reset();
+    }
+
+    typedef system_executor head_type;
+    executor_work_guard<system_executor> head_;
+  };
+
+  template <typename Head>
+  struct composed_work<void(Head)>
+  {
+    typedef composed_io_executors<void(Head)> executors_type;
+
+    explicit composed_work(const executors_type& ex) BOOST_ASIO_NOEXCEPT
+      : head_(ex.head_)
+    {
+    }
+
+    void reset()
+    {
+      head_.reset();
+    }
+
+    typedef Head head_type;
+    executor_work_guard<Head> head_;
+  };
+
+#if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
+
+  template <typename Head, typename... Tail>
+  struct composed_work<void(Head, Tail...)>
+  {
+    typedef composed_io_executors<void(Head, Tail...)> executors_type;
+
+    explicit composed_work(const executors_type& ex) BOOST_ASIO_NOEXCEPT
+      : head_(ex.head_),
+        tail_(ex.tail_)
+    {
+    }
+
+    void reset()
+    {
+      head_.reset();
+      tail_.reset();
+    }
+
+    typedef Head head_type;
+    executor_work_guard<Head> head_;
+    composed_work<void(Tail...)> tail_;
+  };
+
+#else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
+
+#define BOOST_ASIO_PRIVATE_COMPOSED_WORK_DEF(n) \
+  template <typename Head, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
+  struct composed_work<void(Head, BOOST_ASIO_VARIADIC_TARGS(n))> \
+  { \
+    typedef composed_io_executors<void(Head, \
+      BOOST_ASIO_VARIADIC_TARGS(n))> executors_type; \
+  \
+    explicit composed_work(const executors_type& ex) BOOST_ASIO_NOEXCEPT \
+      : head_(ex.head_), \
+        tail_(ex.tail_) \
+    { \
+    } \
+  \
+    void reset() \
+    { \
+      head_.reset(); \
+      tail_.reset(); \
+    } \
+  \
+    typedef Head head_type; \
+    executor_work_guard<Head> head_; \
+    composed_work<void(BOOST_ASIO_VARIADIC_TARGS(n))> tail_; \
+  }; \
+  /**/
   BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_COMPOSED_WORK_DEF)
 #undef BOOST_ASIO_PRIVATE_COMPOSED_WORK_DEF
 
@@ -299,21 +387,46 @@ namespace detail
         function, this_handler->handler_);
   }
 
-  template <typename Signature>
-  struct initiate_composed_op
+  template <typename Signature, typename Executors>
+  class initiate_composed_op
   {
-    template <typename Handler, typename Impl, typename Work>
+  public:
+    typedef typename composed_io_executors<Executors>::head_type executor_type;
+
+    template <typename T>
+    explicit initiate_composed_op(BOOST_ASIO_MOVE_ARG(T) executors)
+      : executors_(BOOST_ASIO_MOVE_CAST(T)(executors))
+    {
+    }
+
+    executor_type get_executor() const BOOST_ASIO_NOEXCEPT
+    {
+      return executors_.head_;
+    }
+
+    template <typename Handler, typename Impl>
     void operator()(BOOST_ASIO_MOVE_ARG(Handler) handler,
-        BOOST_ASIO_MOVE_ARG(Impl) impl,
-        BOOST_ASIO_MOVE_ARG(Work) work) const
+        BOOST_ASIO_MOVE_ARG(Impl) impl) const
     {
-      composed_op<typename decay<Impl>::type, typename decay<Work>::type,
+      composed_op<typename decay<Impl>::type, composed_work<Executors>,
         typename decay<Handler>::type, Signature>(
-          BOOST_ASIO_MOVE_CAST(Impl)(impl), BOOST_ASIO_MOVE_CAST(Work)(work),
+          BOOST_ASIO_MOVE_CAST(Impl)(impl),
+          composed_work<Executors>(executors_),
           BOOST_ASIO_MOVE_CAST(Handler)(handler))();
     }
+
+  private:
+    composed_io_executors<Executors> executors_;
   };
 
+  template <typename Signature, typename Executors>
+  inline initiate_composed_op<Signature, Executors> make_initiate_composed_op(
+      BOOST_ASIO_MOVE_ARG(composed_io_executors<Executors>) executors)
+  {
+    return initiate_composed_op<Signature, Executors>(
+        BOOST_ASIO_MOVE_CAST(composed_io_executors<Executors>)(executors));
+  }
+
   template <typename IoObject>
   inline typename IoObject::executor_type
   get_composed_io_executor(IoObject& io_object)
@@ -334,31 +447,31 @@ namespace detail
 
 template <typename CompletionToken, typename Signature,
     typename Implementation, typename... IoObjectsOrExecutors>
-BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)
+BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, Signature)
 async_compose(BOOST_ASIO_MOVE_ARG(Implementation) implementation,
     BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token,
     BOOST_ASIO_MOVE_ARG(IoObjectsOrExecutors)... io_objects_or_executors)
 {
   return async_initiate<CompletionToken, Signature>(
-      detail::initiate_composed_op<Signature>(), token,
-      BOOST_ASIO_MOVE_CAST(Implementation)(implementation),
-      detail::make_composed_work(
-        detail::get_composed_io_executor(
-          BOOST_ASIO_MOVE_CAST(IoObjectsOrExecutors)(
-            io_objects_or_executors))...));
+      detail::make_initiate_composed_op<Signature>(
+        detail::make_composed_io_executors(
+          detail::get_composed_io_executor(
+            BOOST_ASIO_MOVE_CAST(IoObjectsOrExecutors)(
+              io_objects_or_executors))...)),
+      token, BOOST_ASIO_MOVE_CAST(Implementation)(implementation));
 }
 
 #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
 
 template <typename CompletionToken, typename Signature, typename Implementation>
-BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature)
+BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, Signature)
 async_compose(BOOST_ASIO_MOVE_ARG(Implementation) implementation,
     BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token)
 {
   return async_initiate<CompletionToken, Signature>(
-      detail::initiate_composed_op<Signature>(), token,
-      BOOST_ASIO_MOVE_CAST(Implementation)(implementation),
-      detail::make_composed_work());
+      detail::make_initiate_composed_op<Signature>(
+        detail::make_composed_io_executors()),
+      token, BOOST_ASIO_MOVE_CAST(Implementation)(implementation));
 }
 
 # define BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR(n) \
@@ -388,16 +501,16 @@ async_compose(BOOST_ASIO_MOVE_ARG(Implementation) implementation,
 #define BOOST_ASIO_PRIVATE_ASYNC_COMPOSE_DEF(n) \
   template <typename CompletionToken, typename Signature, \
       typename Implementation, BOOST_ASIO_VARIADIC_TPARAMS(n)> \
-  BOOST_ASIO_INITFN_RESULT_TYPE(CompletionToken, Signature) \
+  BOOST_ASIO_INITFN_AUTO_RESULT_TYPE(CompletionToken, Signature) \
   async_compose(BOOST_ASIO_MOVE_ARG(Implementation) implementation, \
       BOOST_ASIO_NONDEDUCED_MOVE_ARG(CompletionToken) token, \
       BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
   { \
     return async_initiate<CompletionToken, Signature>( \
-        detail::initiate_composed_op<Signature>(), token, \
-        BOOST_ASIO_MOVE_CAST(Implementation)(implementation), \
-        detail::make_composed_work( \
-          BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR(n))); \
+        detail::make_initiate_composed_op<Signature>( \
+          detail::make_composed_io_executors( \
+            BOOST_ASIO_PRIVATE_GET_COMPOSED_IO_EXECUTOR(n))), \
+        token, BOOST_ASIO_MOVE_CAST(Implementation)(implementation)); \
   } \
   /**/
   BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_ASYNC_COMPOSE_DEF)