Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // detached.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_DETACHED_HPP
0012 #define BOOST_ASIO_DETACHED_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 <memory>
0020 #include <boost/asio/detail/type_traits.hpp>
0021 
0022 #include <boost/asio/detail/push_options.hpp>
0023 
0024 namespace boost {
0025 namespace asio {
0026 
0027 /// A @ref completion_token type used to specify that an asynchronous operation
0028 /// is detached.
0029 /**
0030  * The detached_t class is used to indicate that an asynchronous operation is
0031  * detached. That is, there is no completion handler waiting for the
0032  * operation's result. A detached_t object may be passed as a handler to an
0033  * asynchronous operation, typically using the special value
0034  * @c boost::asio::detached. For example:
0035  *
0036  * @code my_socket.async_send(my_buffer, boost::asio::detached);
0037  * @endcode
0038  */
0039 class detached_t
0040 {
0041 public:
0042   /// Constructor. 
0043   constexpr detached_t()
0044   {
0045   }
0046 
0047   /// Adapts an executor to add the @c detached_t completion token as the
0048   /// default.
0049   template <typename InnerExecutor>
0050   struct executor_with_default : InnerExecutor
0051   {
0052     /// Specify @c detached_t as the default completion token type.
0053     typedef detached_t default_completion_token_type;
0054 
0055     /// Construct the adapted executor from the inner executor type.
0056     executor_with_default(const InnerExecutor& ex) noexcept
0057       : InnerExecutor(ex)
0058     {
0059     }
0060 
0061     /// Convert the specified executor to the inner executor type, then use
0062     /// that to construct the adapted executor.
0063     template <typename OtherExecutor>
0064     executor_with_default(const OtherExecutor& ex,
0065         constraint_t<
0066           is_convertible<OtherExecutor, InnerExecutor>::value
0067         > = 0) noexcept
0068       : InnerExecutor(ex)
0069     {
0070     }
0071   };
0072 
0073   /// Type alias to adapt an I/O object to use @c detached_t as its
0074   /// default completion token type.
0075   template <typename T>
0076   using as_default_on_t = typename T::template rebind_executor<
0077       executor_with_default<typename T::executor_type>>::other;
0078 
0079   /// Function helper to adapt an I/O object to use @c detached_t as its
0080   /// default completion token type.
0081   template <typename T>
0082   static typename decay_t<T>::template rebind_executor<
0083       executor_with_default<typename decay_t<T>::executor_type>
0084     >::other
0085   as_default_on(T&& object)
0086   {
0087     return typename decay_t<T>::template rebind_executor<
0088         executor_with_default<typename decay_t<T>::executor_type>
0089       >::other(static_cast<T&&>(object));
0090   }
0091 };
0092 
0093 /// A @ref completion_token object used to specify that an asynchronous
0094 /// operation is detached.
0095 /**
0096  * See the documentation for boost::asio::detached_t for a usage example.
0097  */
0098 constexpr detached_t detached;
0099 
0100 } // namespace asio
0101 } // namespace boost
0102 
0103 #include <boost/asio/detail/pop_options.hpp>
0104 
0105 #include <boost/asio/impl/detached.hpp>
0106 
0107 #endif // BOOST_ASIO_DETACHED_HPP