Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:54

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