Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // impl/consign.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_CONSIGN_HPP
0012 #define BOOST_ASIO_IMPL_CONSIGN_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 consign_t as a completion handler.
0032 template <typename Handler, typename... Values>
0033 class consign_handler
0034 {
0035 public:
0036   typedef void result_type;
0037 
0038   template <typename H>
0039   consign_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     static_cast<Handler&&>(handler_)(static_cast<Args&&>(args)...);
0049   }
0050 
0051 //private:
0052   Handler handler_;
0053   std::tuple<Values...> values_;
0054 };
0055 
0056 template <typename Handler>
0057 inline bool asio_handler_is_continuation(
0058     consign_handler<Handler>* this_handler)
0059 {
0060   return boost_asio_handler_cont_helpers::is_continuation(
0061       this_handler->handler_);
0062 }
0063 
0064 } // namespace detail
0065 
0066 #if !defined(GENERATING_DOCUMENTATION)
0067 
0068 template <typename CompletionToken, typename... Values, typename... Signatures>
0069 struct async_result<consign_t<CompletionToken, Values...>, Signatures...>
0070   : async_result<CompletionToken, Signatures...>
0071 {
0072   template <typename Initiation>
0073   struct init_wrapper
0074   {
0075     init_wrapper(Initiation init)
0076       : initiation_(static_cast<Initiation&&>(init))
0077     {
0078     }
0079 
0080     template <typename Handler, typename... Args>
0081     void operator()(Handler&& handler,
0082         std::tuple<Values...> values, Args&&... args)
0083     {
0084       static_cast<Initiation&&>(initiation_)(
0085           detail::consign_handler<decay_t<Handler>, Values...>(
0086             static_cast<Handler&&>(handler),
0087             static_cast<std::tuple<Values...>&&>(values)),
0088           static_cast<Args&&>(args)...);
0089     }
0090 
0091     Initiation initiation_;
0092   };
0093 
0094   template <typename Initiation, typename RawCompletionToken, typename... Args>
0095   static auto initiate(Initiation&& initiation,
0096       RawCompletionToken&& token, Args&&... args)
0097     -> decltype(
0098       async_initiate<CompletionToken, Signatures...>(
0099         init_wrapper<decay_t<Initiation>>(
0100           static_cast<Initiation&&>(initiation)),
0101         token.token_, static_cast<std::tuple<Values...>&&>(token.values_),
0102         static_cast<Args&&>(args)...))
0103   {
0104     return async_initiate<CompletionToken, Signatures...>(
0105         init_wrapper<decay_t<Initiation>>(
0106           static_cast<Initiation&&>(initiation)),
0107         token.token_, static_cast<std::tuple<Values...>&&>(token.values_),
0108         static_cast<Args&&>(args)...);
0109   }
0110 };
0111 
0112 template <template <typename, typename> class Associator,
0113     typename Handler, typename... Values, typename DefaultCandidate>
0114 struct associator<Associator,
0115     detail::consign_handler<Handler, Values...>, DefaultCandidate>
0116   : Associator<Handler, DefaultCandidate>
0117 {
0118   static typename Associator<Handler, DefaultCandidate>::type get(
0119       const detail::consign_handler<Handler, Values...>& h) noexcept
0120   {
0121     return Associator<Handler, DefaultCandidate>::get(h.handler_);
0122   }
0123 
0124   static auto get(const detail::consign_handler<Handler, Values...>& h,
0125       const DefaultCandidate& c) noexcept
0126     -> decltype(Associator<Handler, DefaultCandidate>::get(h.handler_, c))
0127   {
0128     return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
0129   }
0130 };
0131 
0132 #endif // !defined(GENERATING_DOCUMENTATION)
0133 
0134 } // namespace asio
0135 } // namespace boost
0136 
0137 #include <boost/asio/detail/pop_options.hpp>
0138 
0139 #endif // BOOST_ASIO_IMPL_CONSIGN_HPP