Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:33:38

0001 //
0002 // 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_AS_TUPLE_HPP
0012 #define BOOST_ASIO_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 <boost/asio/detail/type_traits.hpp>
0020 
0021 #include <boost/asio/detail/push_options.hpp>
0022 
0023 namespace boost {
0024 namespace asio {
0025 
0026 /// A @ref completion_token adapter used to specify that the completion handler
0027 /// arguments should be combined into a single tuple argument.
0028 /**
0029  * The as_tuple_t class is used to indicate that any arguments to the
0030  * completion handler should be combined and passed as a single tuple argument.
0031  * The arguments are first moved into a @c std::tuple and that tuple is then
0032  * passed to the completion handler.
0033  */
0034 template <typename CompletionToken>
0035 class as_tuple_t
0036 {
0037 public:
0038   /// Tag type used to prevent the "default" constructor from being used for
0039   /// conversions.
0040   struct default_constructor_tag {};
0041 
0042   /// Default constructor.
0043   /**
0044    * This constructor is only valid if the underlying completion token is
0045    * default constructible and move constructible. The underlying completion
0046    * token is itself defaulted as an argument to allow it to capture a source
0047    * location.
0048    */
0049   constexpr as_tuple_t(
0050       default_constructor_tag = default_constructor_tag(),
0051       CompletionToken token = CompletionToken())
0052     : token_(static_cast<CompletionToken&&>(token))
0053   {
0054   }
0055 
0056   /// Constructor.
0057   template <typename T>
0058   constexpr explicit as_tuple_t(
0059       T&& completion_token)
0060     : token_(static_cast<T&&>(completion_token))
0061   {
0062   }
0063 
0064   /// Adapts an executor to add the @c as_tuple_t completion token as the
0065   /// default.
0066   template <typename InnerExecutor>
0067   struct executor_with_default : InnerExecutor
0068   {
0069     /// Specify @c as_tuple_t as the default completion token type.
0070     typedef as_tuple_t default_completion_token_type;
0071 
0072     /// Construct the adapted executor from the inner executor type.
0073     template <typename InnerExecutor1>
0074     executor_with_default(const InnerExecutor1& ex,
0075         constraint_t<
0076           conditional_t<
0077             !is_same<InnerExecutor1, executor_with_default>::value,
0078             is_convertible<InnerExecutor1, InnerExecutor>,
0079             false_type
0080           >::value
0081         > = 0) noexcept
0082       : InnerExecutor(ex)
0083     {
0084     }
0085   };
0086 
0087   /// Type alias to adapt an I/O object to use @c as_tuple_t as its
0088   /// default completion token type.
0089   template <typename T>
0090   using as_default_on_t = typename T::template rebind_executor<
0091       executor_with_default<typename T::executor_type>>::other;
0092 
0093   /// Function helper to adapt an I/O object to use @c as_tuple_t as its
0094   /// default completion token type.
0095   template <typename T>
0096   static typename decay_t<T>::template rebind_executor<
0097       executor_with_default<typename decay_t<T>::executor_type>
0098     >::other
0099   as_default_on(T&& object)
0100   {
0101     return typename decay_t<T>::template rebind_executor<
0102         executor_with_default<typename decay_t<T>::executor_type>
0103       >::other(static_cast<T&&>(object));
0104   }
0105 
0106 //private:
0107   CompletionToken token_;
0108 };
0109 
0110 /// Adapt a @ref completion_token to specify that the completion handler
0111 /// arguments should be combined into a single tuple argument.
0112 template <typename CompletionToken>
0113 BOOST_ASIO_NODISCARD inline
0114 constexpr as_tuple_t<decay_t<CompletionToken>>
0115 as_tuple(CompletionToken&& completion_token)
0116 {
0117   return as_tuple_t<decay_t<CompletionToken>>(
0118       static_cast<CompletionToken&&>(completion_token));
0119 }
0120 
0121 } // namespace asio
0122 } // namespace boost
0123 
0124 #include <boost/asio/detail/pop_options.hpp>
0125 
0126 #include <boost/asio/impl/as_tuple.hpp>
0127 
0128 #endif // BOOST_ASIO_AS_TUPLE_HPP