Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // impl/prepend.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_PREPEND_HPP
0012 #define BOOST_ASIO_IMPL_PREPEND_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 <boost/asio/associator.hpp>
0020 #include <boost/asio/async_result.hpp>
0021 #include <boost/asio/detail/handler_cont_helpers.hpp>
0022 #include <boost/asio/detail/type_traits.hpp>
0023 #include <boost/asio/detail/utility.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 prepend_t as a completion handler.
0032 template <typename Handler, typename... Values>
0033 class prepend_handler
0034 {
0035 public:
0036   typedef void result_type;
0037 
0038   template <typename H>
0039   prepend_handler(H&& handler, std::tuple<Values...> values)
0040     : handler_(static_cast<H&&>(handler)),
0041       values_(static_cast<std::tuple<Values...>&&>(values))
0042   {
0043   }
0044 
0045   template <typename... Args>
0046   void operator()(Args&&... args)
0047   {
0048     this->invoke(
0049         index_sequence_for<Values...>{},
0050         static_cast<Args&&>(args)...);
0051   }
0052 
0053   template <std::size_t... I, typename... Args>
0054   void invoke(index_sequence<I...>, Args&&... args)
0055   {
0056     static_cast<Handler&&>(handler_)(
0057         static_cast<Values&&>(std::get<I>(values_))...,
0058         static_cast<Args&&>(args)...);
0059   }
0060 
0061 //private:
0062   Handler handler_;
0063   std::tuple<Values...> values_;
0064 };
0065 
0066 template <typename Handler>
0067 inline bool asio_handler_is_continuation(
0068     prepend_handler<Handler>* this_handler)
0069 {
0070   return boost_asio_handler_cont_helpers::is_continuation(
0071         this_handler->handler_);
0072 }
0073 
0074 template <typename Signature, typename... Values>
0075 struct prepend_signature;
0076 
0077 template <typename R, typename... Args, typename... Values>
0078 struct prepend_signature<R(Args...), Values...>
0079 {
0080   typedef R type(Values..., decay_t<Args>...);
0081 };
0082 
0083 } // namespace detail
0084 
0085 #if !defined(GENERATING_DOCUMENTATION)
0086 
0087 template <typename CompletionToken, typename... Values, typename Signature>
0088 struct async_result<
0089     prepend_t<CompletionToken, Values...>, Signature>
0090   : async_result<CompletionToken,
0091       typename detail::prepend_signature<
0092         Signature, Values...>::type>
0093 {
0094   typedef typename detail::prepend_signature<
0095       Signature, Values...>::type signature;
0096 
0097   template <typename Initiation>
0098   struct init_wrapper
0099   {
0100     init_wrapper(Initiation init)
0101       : initiation_(static_cast<Initiation&&>(init))
0102     {
0103     }
0104 
0105     template <typename Handler, typename... Args>
0106     void operator()(Handler&& handler,
0107         std::tuple<Values...> values, Args&&... args)
0108     {
0109       static_cast<Initiation&&>(initiation_)(
0110           detail::prepend_handler<decay_t<Handler>, Values...>(
0111             static_cast<Handler&&>(handler),
0112             static_cast<std::tuple<Values...>&&>(values)),
0113           static_cast<Args&&>(args)...);
0114     }
0115 
0116     Initiation initiation_;
0117   };
0118 
0119   template <typename Initiation, typename RawCompletionToken, typename... Args>
0120   static auto initiate(Initiation&& initiation,
0121       RawCompletionToken&& token, Args&&... args)
0122     -> decltype(
0123       async_initiate<CompletionToken, signature>(
0124         declval<init_wrapper<decay_t<Initiation>>>(),
0125         token.token_,
0126         static_cast<std::tuple<Values...>&&>(token.values_),
0127         static_cast<Args&&>(args)...))
0128   {
0129     return async_initiate<CompletionToken, signature>(
0130         init_wrapper<decay_t<Initiation>>(
0131           static_cast<Initiation&&>(initiation)),
0132         token.token_,
0133         static_cast<std::tuple<Values...>&&>(token.values_),
0134         static_cast<Args&&>(args)...);
0135   }
0136 };
0137 
0138 template <template <typename, typename> class Associator,
0139     typename Handler, typename... Values, typename DefaultCandidate>
0140 struct associator<Associator,
0141     detail::prepend_handler<Handler, Values...>, DefaultCandidate>
0142   : Associator<Handler, DefaultCandidate>
0143 {
0144   static typename Associator<Handler, DefaultCandidate>::type get(
0145       const detail::prepend_handler<Handler, Values...>& h) noexcept
0146   {
0147     return Associator<Handler, DefaultCandidate>::get(h.handler_);
0148   }
0149 
0150   static auto get(const detail::prepend_handler<Handler, Values...>& h,
0151       const DefaultCandidate& c) noexcept
0152     -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
0153   {
0154     return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
0155   }
0156 };
0157 
0158 #endif // !defined(GENERATING_DOCUMENTATION)
0159 
0160 } // namespace asio
0161 } // namespace boost
0162 
0163 #include <boost/asio/detail/pop_options.hpp>
0164 
0165 #endif // BOOST_ASIO_IMPL_PREPEND_HPP