Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/asio/redirect_error.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // redirect_error.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_ERROR_HPP
0012 #define BOOST_ASIO_REDIRECT_ERROR_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/system/error_code.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 an error produced by an
0028 /// asynchronous operation is captured to an error_code variable.
0029 /**
0030  * The redirect_error_t class is used to indicate that any error_code produced
0031  * by an asynchronous operation is captured to a specified variable.
0032  */
0033 template <typename CompletionToken>
0034 class redirect_error_t
0035 {
0036 public:
0037   /// Constructor.
0038   template <typename T>
0039   redirect_error_t(T&& completion_token, boost::system::error_code& ec)
0040     : token_(static_cast<T&&>(completion_token)),
0041       ec_(ec)
0042   {
0043   }
0044 
0045 //private:
0046   CompletionToken token_;
0047   boost::system::error_code& ec_;
0048 };
0049 
0050 /// A function object type that adapts a @ref completion_token to capture
0051 /// error_code values 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 class partial_redirect_error
0058 {
0059 public:
0060   /// Constructor that specifies the variable used to capture error_code values.
0061   explicit partial_redirect_error(boost::system::error_code& ec)
0062     : ec_(ec)
0063   {
0064   }
0065 
0066   /// Adapt a @ref completion_token to specify that the completion handler
0067   /// should capture error_code values to a variable.
0068   template <typename CompletionToken>
0069   BOOST_ASIO_NODISCARD inline
0070   constexpr redirect_error_t<decay_t<CompletionToken>>
0071   operator()(CompletionToken&& completion_token) const
0072   {
0073     return redirect_error_t<decay_t<CompletionToken>>(
0074         static_cast<CompletionToken&&>(completion_token), ec_);
0075   }
0076 
0077 //private:
0078   boost::system::error_code& ec_;
0079 };
0080 
0081 /// Create a partial completion token adapter that captures error_code values
0082 /// to a variable.
0083 BOOST_ASIO_NODISCARD inline partial_redirect_error
0084 redirect_error(boost::system::error_code& ec)
0085 {
0086   return partial_redirect_error(ec);
0087 }
0088 
0089 /// Adapt a @ref completion_token to capture error_code values to a variable.
0090 template <typename CompletionToken>
0091 BOOST_ASIO_NODISCARD inline redirect_error_t<decay_t<CompletionToken>>
0092 redirect_error(CompletionToken&& completion_token,
0093     boost::system::error_code& ec)
0094 {
0095   return redirect_error_t<decay_t<CompletionToken>>(
0096       static_cast<CompletionToken&&>(completion_token), ec);
0097 }
0098 
0099 } // namespace asio
0100 } // namespace boost
0101 
0102 #include <boost/asio/detail/pop_options.hpp>
0103 
0104 #include <boost/asio/impl/redirect_error.hpp>
0105 
0106 #endif // BOOST_ASIO_REDIRECT_ERROR_HPP