Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-09 08:05:08

0001 //
0002 // impl/as_tuple.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_AS_TUPLE_HPP
0012 #define BOOST_ASIO_IMPL_AS_TUPLE_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/associated_executor.hpp>
0021 #include <boost/asio/associator.hpp>
0022 #include <boost/asio/async_result.hpp>
0023 #include <boost/asio/detail/handler_cont_helpers.hpp>
0024 #include <boost/asio/detail/initiation_base.hpp>
0025 #include <boost/asio/detail/type_traits.hpp>
0026 
0027 #include <boost/asio/detail/push_options.hpp>
0028 
0029 namespace boost {
0030 namespace asio {
0031 namespace detail {
0032 
0033 // Class to adapt a as_tuple_t as a completion handler.
0034 template <typename Handler>
0035 class as_tuple_handler
0036 {
0037 public:
0038   typedef void result_type;
0039 
0040   template <typename CompletionToken>
0041   as_tuple_handler(as_tuple_t<CompletionToken> e)
0042     : handler_(static_cast<CompletionToken&&>(e.token_))
0043   {
0044   }
0045 
0046   template <typename RedirectedHandler>
0047   as_tuple_handler(RedirectedHandler&& h)
0048     : handler_(static_cast<RedirectedHandler&&>(h))
0049   {
0050   }
0051 
0052   template <typename... Args>
0053   void operator()(Args&&... args)
0054   {
0055     static_cast<Handler&&>(handler_)(
0056         std::make_tuple(static_cast<Args&&>(args)...));
0057   }
0058 
0059 //private:
0060   Handler handler_;
0061 };
0062 
0063 template <typename Handler>
0064 inline bool asio_handler_is_continuation(
0065     as_tuple_handler<Handler>* this_handler)
0066 {
0067   return boost_asio_handler_cont_helpers::is_continuation(
0068         this_handler->handler_);
0069 }
0070 
0071 template <typename Signature>
0072 struct as_tuple_signature;
0073 
0074 template <typename R, typename... Args>
0075 struct as_tuple_signature<R(Args...)>
0076 {
0077   typedef R type(std::tuple<decay_t<Args>...>);
0078 };
0079 
0080 template <typename R, typename... Args>
0081 struct as_tuple_signature<R(Args...) &>
0082 {
0083   typedef R type(std::tuple<decay_t<Args>...>) &;
0084 };
0085 
0086 template <typename R, typename... Args>
0087 struct as_tuple_signature<R(Args...) &&>
0088 {
0089   typedef R type(std::tuple<decay_t<Args>...>) &&;
0090 };
0091 
0092 #if defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0093 
0094 template <typename R, typename... Args>
0095 struct as_tuple_signature<R(Args...) noexcept>
0096 {
0097   typedef R type(std::tuple<decay_t<Args>...>) noexcept;
0098 };
0099 
0100 template <typename R, typename... Args>
0101 struct as_tuple_signature<R(Args...) & noexcept>
0102 {
0103   typedef R type(std::tuple<decay_t<Args>...>) & noexcept;
0104 };
0105 
0106 template <typename R, typename... Args>
0107 struct as_tuple_signature<R(Args...) && noexcept>
0108 {
0109   typedef R type(std::tuple<decay_t<Args>...>) && noexcept;
0110 };
0111 
0112 #endif // defined(BOOST_ASIO_HAS_NOEXCEPT_FUNCTION_TYPE)
0113 
0114 } // namespace detail
0115 
0116 #if !defined(GENERATING_DOCUMENTATION)
0117 
0118 template <typename CompletionToken, typename... Signatures>
0119 struct async_result<as_tuple_t<CompletionToken>, Signatures...>
0120   : async_result<CompletionToken,
0121       typename detail::as_tuple_signature<Signatures>::type...>
0122 {
0123   template <typename Initiation>
0124   struct init_wrapper : detail::initiation_base<Initiation>
0125   {
0126     using detail::initiation_base<Initiation>::initiation_base;
0127 
0128     template <typename Handler, typename... Args>
0129     void operator()(Handler&& handler, Args&&... args) &&
0130     {
0131       static_cast<Initiation&&>(*this)(
0132           detail::as_tuple_handler<decay_t<Handler>>(
0133             static_cast<Handler&&>(handler)),
0134           static_cast<Args&&>(args)...);
0135     }
0136 
0137     template <typename Handler, typename... Args>
0138     void operator()(Handler&& handler, Args&&... args) const &
0139     {
0140       static_cast<const Initiation&>(*this)(
0141           detail::as_tuple_handler<decay_t<Handler>>(
0142             static_cast<Handler&&>(handler)),
0143           static_cast<Args&&>(args)...);
0144     }
0145   };
0146 
0147   template <typename Initiation, typename RawCompletionToken, typename... Args>
0148   static auto initiate(Initiation&& initiation,
0149       RawCompletionToken&& token, Args&&... args)
0150     -> decltype(
0151       async_initiate<
0152         conditional_t<
0153           is_const<remove_reference_t<RawCompletionToken>>::value,
0154             const CompletionToken, CompletionToken>,
0155         typename detail::as_tuple_signature<Signatures>::type...>(
0156           init_wrapper<decay_t<Initiation>>(
0157             static_cast<Initiation&&>(initiation)),
0158           token.token_, static_cast<Args&&>(args)...))
0159   {
0160     return async_initiate<
0161       conditional_t<
0162         is_const<remove_reference_t<RawCompletionToken>>::value,
0163           const CompletionToken, CompletionToken>,
0164       typename detail::as_tuple_signature<Signatures>::type...>(
0165         init_wrapper<decay_t<Initiation>>(
0166           static_cast<Initiation&&>(initiation)),
0167         token.token_, static_cast<Args&&>(args)...);
0168   }
0169 };
0170 
0171 #if defined(BOOST_ASIO_MSVC)
0172 
0173 // Workaround for MSVC internal compiler error.
0174 
0175 template <typename CompletionToken, typename Signature>
0176 struct async_result<as_tuple_t<CompletionToken>, Signature>
0177   : async_result<CompletionToken,
0178       typename detail::as_tuple_signature<Signature>::type>
0179 {
0180   template <typename Initiation>
0181   struct init_wrapper : detail::initiation_base<Initiation>
0182   {
0183     using detail::initiation_base<Initiation>::initiation_base;
0184 
0185     template <typename Handler, typename... Args>
0186     void operator()(Handler&& handler, Args&&... args) &&
0187     {
0188       static_cast<Initiation&&>(*this)(
0189           detail::as_tuple_handler<decay_t<Handler>>(
0190             static_cast<Handler&&>(handler)),
0191           static_cast<Args&&>(args)...);
0192     }
0193 
0194     template <typename Handler, typename... Args>
0195     void operator()(Handler&& handler, Args&&... args) const &
0196     {
0197       static_cast<const Initiation&>(*this)(
0198           detail::as_tuple_handler<decay_t<Handler>>(
0199             static_cast<Handler&&>(handler)),
0200           static_cast<Args&&>(args)...);
0201     }
0202   };
0203 
0204   template <typename Initiation, typename RawCompletionToken, typename... Args>
0205   static auto initiate(Initiation&& initiation,
0206       RawCompletionToken&& token, Args&&... args)
0207     -> decltype(
0208       async_initiate<
0209         conditional_t<
0210           is_const<remove_reference_t<RawCompletionToken>>::value,
0211             const CompletionToken, CompletionToken>,
0212         typename detail::as_tuple_signature<Signature>::type>(
0213           init_wrapper<decay_t<Initiation>>(
0214             static_cast<Initiation&&>(initiation)),
0215           token.token_, static_cast<Args&&>(args)...))
0216   {
0217     return async_initiate<
0218       conditional_t<
0219         is_const<remove_reference_t<RawCompletionToken>>::value,
0220           const CompletionToken, CompletionToken>,
0221       typename detail::as_tuple_signature<Signature>::type>(
0222         init_wrapper<decay_t<Initiation>>(
0223           static_cast<Initiation&&>(initiation)),
0224         token.token_, static_cast<Args&&>(args)...);
0225   }
0226 };
0227 
0228 #endif // defined(BOOST_ASIO_MSVC)
0229 
0230 template <template <typename, typename> class Associator,
0231     typename Handler, typename DefaultCandidate>
0232 struct associator<Associator,
0233     detail::as_tuple_handler<Handler>, DefaultCandidate>
0234   : Associator<Handler, DefaultCandidate>
0235 {
0236   static typename Associator<Handler, DefaultCandidate>::type get(
0237       const detail::as_tuple_handler<Handler>& h) noexcept
0238   {
0239     return Associator<Handler, DefaultCandidate>::get(h.handler_);
0240   }
0241 
0242   static auto get(const detail::as_tuple_handler<Handler>& h,
0243       const DefaultCandidate& c) noexcept
0244     -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
0245   {
0246     return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
0247   }
0248 };
0249 
0250 template <typename... Signatures>
0251 struct async_result<partial_as_tuple, Signatures...>
0252 {
0253   template <typename Initiation, typename RawCompletionToken, typename... Args>
0254   static auto initiate(Initiation&& initiation,
0255       RawCompletionToken&&, Args&&... args)
0256     -> decltype(
0257       async_initiate<Signatures...>(
0258         static_cast<Initiation&&>(initiation),
0259         as_tuple_t<
0260           default_completion_token_t<associated_executor_t<Initiation>>>{},
0261         static_cast<Args&&>(args)...))
0262   {
0263     return async_initiate<Signatures...>(
0264         static_cast<Initiation&&>(initiation),
0265         as_tuple_t<
0266           default_completion_token_t<associated_executor_t<Initiation>>>{},
0267         static_cast<Args&&>(args)...);
0268   }
0269 };
0270 
0271 #endif // !defined(GENERATING_DOCUMENTATION)
0272 
0273 } // namespace asio
0274 } // namespace boost
0275 
0276 #include <boost/asio/detail/pop_options.hpp>
0277 
0278 #endif // BOOST_ASIO_IMPL_AS_TUPLE_HPP