Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //
0002 // redirect_error.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_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 /// Adapt a @ref completion_token to capture error_code values to a variable.
0051 template <typename CompletionToken>
0052 inline redirect_error_t<decay_t<CompletionToken>> redirect_error(
0053     CompletionToken&& completion_token, boost::system::error_code& ec)
0054 {
0055   return redirect_error_t<decay_t<CompletionToken>>(
0056       static_cast<CompletionToken&&>(completion_token), ec);
0057 }
0058 
0059 } // namespace asio
0060 } // namespace boost
0061 
0062 #include <boost/asio/detail/pop_options.hpp>
0063 
0064 #include <boost/asio/impl/redirect_error.hpp>
0065 
0066 #endif // BOOST_ASIO_REDIRECT_ERROR_HPP