Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // experimental/detail/channel_message.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_EXPERIMENTAL_DETAIL_CHANNEL_MESSAGE_HPP
0012 #define BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_MESSAGE_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/detail/type_traits.hpp>
0021 #include <boost/asio/detail/utility.hpp>
0022 
0023 #include <boost/asio/detail/push_options.hpp>
0024 
0025 namespace boost {
0026 namespace asio {
0027 namespace experimental {
0028 namespace detail {
0029 
0030 template <typename Signature>
0031 class channel_message;
0032 
0033 template <typename R>
0034 class channel_message<R()>
0035 {
0036 public:
0037   channel_message(int)
0038   {
0039   }
0040 
0041   template <typename Handler>
0042   void receive(Handler& handler)
0043   {
0044     static_cast<Handler&&>(handler)();
0045   }
0046 };
0047 
0048 template <typename R, typename Arg0>
0049 class channel_message<R(Arg0)>
0050 {
0051 public:
0052   template <typename T0>
0053   channel_message(int, T0&& t0)
0054     : arg0_(static_cast<T0&&>(t0))
0055   {
0056   }
0057 
0058   template <typename Handler>
0059   void receive(Handler& handler)
0060   {
0061     static_cast<Handler&&>(handler)(
0062         static_cast<arg0_type&&>(arg0_));
0063   }
0064 
0065 private:
0066   typedef decay_t<Arg0> arg0_type;
0067   arg0_type arg0_;
0068 };
0069 
0070 template <typename R, typename Arg0, typename Arg1>
0071 class channel_message<R(Arg0, Arg1)>
0072 {
0073 public:
0074   template <typename T0, typename T1>
0075   channel_message(int, T0&& t0, T1&& t1)
0076     : arg0_(static_cast<T0&&>(t0)),
0077       arg1_(static_cast<T1&&>(t1))
0078   {
0079   }
0080 
0081   template <typename Handler>
0082   void receive(Handler& handler)
0083   {
0084     static_cast<Handler&&>(handler)(
0085         static_cast<arg0_type&&>(arg0_),
0086         static_cast<arg1_type&&>(arg1_));
0087   }
0088 
0089 private:
0090   typedef decay_t<Arg0> arg0_type;
0091   arg0_type arg0_;
0092   typedef decay_t<Arg1> arg1_type;
0093   arg1_type arg1_;
0094 };
0095 
0096 template <typename R, typename... Args>
0097 class channel_message<R(Args...)>
0098 {
0099 public:
0100   template <typename... T>
0101   channel_message(int, T&&... t)
0102     : args_(static_cast<T&&>(t)...)
0103   {
0104   }
0105 
0106   template <typename Handler>
0107   void receive(Handler& h)
0108   {
0109     this->do_receive(h, boost::asio::detail::index_sequence_for<Args...>());
0110   }
0111 
0112 private:
0113   template <typename Handler, std::size_t... I>
0114   void do_receive(Handler& h, boost::asio::detail::index_sequence<I...>)
0115   {
0116     static_cast<Handler&&>(h)(
0117         std::get<I>(static_cast<args_type&&>(args_))...);
0118   }
0119 
0120   typedef std::tuple<decay_t<Args>...> args_type;
0121   args_type args_;
0122 };
0123 
0124 } // namespace detail
0125 } // namespace experimental
0126 } // namespace asio
0127 } // namespace boost
0128 
0129 #include <boost/asio/detail/pop_options.hpp>
0130 
0131 #endif // BOOST_ASIO_EXPERIMENTAL_DETAIL_CHANNEL_MESSAGE_HPP