Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 08:38:35

0001 //
0002 // redirect_disposition.hpp
0003 // ~~~~~~~~~~~~~~~~~~~~~~~~
0004 //
0005 // Copyright (c) 2003-2025 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_REDIRECT_DISPOSITION_HPP
0012 #define BOOST_ASIO_REDIRECT_DISPOSITION_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 #include <boost/asio/disposition.hpp>
0021 
0022 #include <boost/asio/detail/push_options.hpp>
0023 
0024 namespace boost {
0025 namespace asio {
0026 
0027 /// A @ref completion_token adapter used to specify that the disposition
0028 /// produced by an asynchronous operation is captured to a variable.
0029 /**
0030  * The redirect_disposition_t class is used to indicate that any disposition
0031  * produced by an asynchronous operation is captured to a specified variable.
0032  */
0033 template <typename CompletionToken, BOOST_ASIO_DISPOSITION Disposition>
0034 class redirect_disposition_t
0035 {
0036 public:
0037   /// Constructor.
0038   template <typename T>
0039   redirect_disposition_t(T&& completion_token, Disposition& d)
0040     : token_(static_cast<T&&>(completion_token)),
0041       d_(d)
0042   {
0043   }
0044 
0045 //private:
0046   CompletionToken token_;
0047   Disposition& d_;
0048 };
0049 
0050 /// A function object type that adapts a @ref completion_token to capture
0051 /// any disposition produced by an asynchronous operation to a variable.
0052 /**
0053  * May also be used directly as a completion token, in which case it adapts the
0054  * asynchronous operation's default completion token (or boost::asio::deferred
0055  * if no default is available).
0056  */
0057 template <BOOST_ASIO_DISPOSITION Disposition>
0058 class partial_redirect_disposition
0059 {
0060 public:
0061   /// Constructor that specifies the variable used to capture disposition
0062   /// values.
0063   explicit partial_redirect_disposition(Disposition& d)
0064     : d_(d)
0065   {
0066   }
0067 
0068   /// Adapt a @ref completion_token to specify that the completion handler
0069   /// should capture disposition values to a variable.
0070   template <typename CompletionToken>
0071   BOOST_ASIO_NODISCARD inline
0072   constexpr redirect_disposition_t<decay_t<CompletionToken>, Disposition>
0073   operator()(CompletionToken&& completion_token) const
0074   {
0075     return redirect_disposition_t<decay_t<CompletionToken>, Disposition>(
0076         static_cast<CompletionToken&&>(completion_token), d_);
0077   }
0078 
0079 //private:
0080   Disposition& d_;
0081 };
0082 
0083 /// Create a partial completion token adapter that captures disposition values
0084 /// to a variable.
0085 /**
0086  * @note When redirecting to a variable of type @c std::exception_ptr, other
0087  * disposition types will be automatically converted to @c std::exception_ptr.
0088  */
0089 template <BOOST_ASIO_DISPOSITION Disposition>
0090 BOOST_ASIO_NODISCARD inline partial_redirect_disposition<Disposition>
0091 redirect_disposition(Disposition& d)
0092 {
0093   return partial_redirect_disposition<Disposition>(d);
0094 }
0095 
0096 /// Adapt a @ref completion_token to capture disposition values to a variable.
0097 /**
0098  * @note When redirecting to a variable of type @c std::exception_ptr, other
0099  * disposition types will be automatically converted to @c std::exception_ptr.
0100  */
0101 template <typename CompletionToken, BOOST_ASIO_DISPOSITION Disposition>
0102 BOOST_ASIO_NODISCARD inline
0103 redirect_disposition_t<decay_t<CompletionToken>, Disposition>
0104 redirect_disposition(CompletionToken&& completion_token, Disposition& d)
0105 {
0106   return redirect_disposition_t<decay_t<CompletionToken>, Disposition>(
0107       static_cast<CompletionToken&&>(completion_token), d);
0108 }
0109 
0110 } // namespace asio
0111 } // namespace boost
0112 
0113 #include <boost/asio/detail/pop_options.hpp>
0114 
0115 #include <boost/asio/impl/redirect_disposition.hpp>
0116 
0117 #endif // BOOST_ASIO_REDIRECT_DISPOSITION_HPP