Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:27:24

0001 //
0002 // experimental/impl/as_single.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com)
0006 //
0007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0009 //
0010 
0011 #ifndef BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_HPP
0012 #define BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_HPP
0013 
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 
0018 #include <boost/asio/detail/config.hpp>
0019 #include <tuple>
0020 #include <boost/asio/associator.hpp>
0021 #include <boost/asio/async_result.hpp>
0022 #include <boost/asio/detail/handler_cont_helpers.hpp>
0023 #include <boost/asio/detail/initiation_base.hpp>
0024 #include <boost/asio/detail/type_traits.hpp>
0025 
0026 #include <boost/asio/detail/push_options.hpp>
0027 
0028 namespace boost {
0029 namespace asio {
0030 namespace experimental {
0031 namespace detail {
0032 
0033 // Class to adapt a as_single_t as a completion handler.
0034 template <typename Handler>
0035 class as_single_handler
0036 {
0037 public:
0038   typedef void result_type;
0039 
0040   template <typename CompletionToken>
0041   as_single_handler(as_single_t<CompletionToken> e)
0042     : handler_(static_cast<CompletionToken&&>(e.token_))
0043   {
0044   }
0045 
0046   template <typename RedirectedHandler>
0047   as_single_handler(RedirectedHandler&& h)
0048     : handler_(static_cast<RedirectedHandler&&>(h))
0049   {
0050   }
0051 
0052   void operator()()
0053   {
0054     static_cast<Handler&&>(handler_)();
0055   }
0056 
0057   template <typename Arg>
0058   void operator()(Arg&& arg)
0059   {
0060     static_cast<Handler&&>(handler_)(static_cast<Arg&&>(arg));
0061   }
0062 
0063   template <typename... Args>
0064   void operator()(Args&&... args)
0065   {
0066     static_cast<Handler&&>(handler_)(
0067         std::make_tuple(static_cast<Args&&>(args)...));
0068   }
0069 
0070 //private:
0071   Handler handler_;
0072 };
0073 
0074 template <typename Handler>
0075 inline bool asio_handler_is_continuation(
0076     as_single_handler<Handler>* this_handler)
0077 {
0078   return boost_asio_handler_cont_helpers::is_continuation(
0079         this_handler->handler_);
0080 }
0081 
0082 template <typename Signature>
0083 struct as_single_signature
0084 {
0085   typedef Signature type;
0086 };
0087 
0088 template <typename R>
0089 struct as_single_signature<R()>
0090 {
0091   typedef R type();
0092 };
0093 
0094 template <typename R, typename Arg>
0095 struct as_single_signature<R(Arg)>
0096 {
0097   typedef R type(Arg);
0098 };
0099 
0100 template <typename R, typename... Args>
0101 struct as_single_signature<R(Args...)>
0102 {
0103   typedef R type(std::tuple<decay_t<Args>...>);
0104 };
0105 
0106 } // namespace detail
0107 } // namespace experimental
0108 
0109 #if !defined(GENERATING_DOCUMENTATION)
0110 
0111 template <typename CompletionToken, typename Signature>
0112 struct async_result<experimental::as_single_t<CompletionToken>, Signature>
0113 {
0114   template <typename Initiation>
0115   struct init_wrapper : detail::initiation_base<Initiation>
0116   {
0117     using detail::initiation_base<Initiation>::initiation_base;
0118 
0119     template <typename Handler, typename... Args>
0120     void operator()(Handler&& handler, Args&&... args) &&
0121     {
0122       static_cast<Initiation&&>(*this)(
0123           experimental::detail::as_single_handler<decay_t<Handler>>(
0124             static_cast<Handler&&>(handler)),
0125           static_cast<Args&&>(args)...);
0126     }
0127 
0128     template <typename Handler, typename... Args>
0129     void operator()(Handler&& handler, Args&&... args) const &
0130     {
0131       static_cast<const Initiation&>(*this)(
0132           experimental::detail::as_single_handler<decay_t<Handler>>(
0133             static_cast<Handler&&>(handler)),
0134           static_cast<Args&&>(args)...);
0135     }
0136   };
0137 
0138   template <typename Initiation, typename RawCompletionToken, typename... Args>
0139   static auto initiate(Initiation&& initiation,
0140       RawCompletionToken&& token, Args&&... args)
0141     -> decltype(
0142       async_initiate<CompletionToken,
0143         typename experimental::detail::as_single_signature<Signature>::type>(
0144           init_wrapper<decay_t<Initiation>>(
0145             static_cast<Initiation&&>(initiation)),
0146           token.token_, static_cast<Args&&>(args)...))
0147   {
0148     return async_initiate<CompletionToken,
0149       typename experimental::detail::as_single_signature<Signature>::type>(
0150         init_wrapper<decay_t<Initiation>>(
0151           static_cast<Initiation&&>(initiation)),
0152         token.token_, static_cast<Args&&>(args)...);
0153   }
0154 };
0155 
0156 template <template <typename, typename> class Associator,
0157     typename Handler, typename DefaultCandidate>
0158 struct associator<Associator,
0159     experimental::detail::as_single_handler<Handler>, DefaultCandidate>
0160   : Associator<Handler, DefaultCandidate>
0161 {
0162   static typename Associator<Handler, DefaultCandidate>::type get(
0163       const experimental::detail::as_single_handler<Handler>& h) noexcept
0164   {
0165     return Associator<Handler, DefaultCandidate>::get(h.handler_);
0166   }
0167 
0168   static auto get(const experimental::detail::as_single_handler<Handler>& h,
0169       const DefaultCandidate& c) noexcept
0170     -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
0171   {
0172     return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
0173   }
0174 };
0175 
0176 #endif // !defined(GENERATING_DOCUMENTATION)
0177 
0178 } // namespace asio
0179 } // namespace boost
0180 
0181 #include <boost/asio/detail/pop_options.hpp>
0182 
0183 #endif // BOOST_ASIO_IMPL_EXPERIMENTAL_AS_SINGLE_HPP