Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-15 08:28:26

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