1 | // |
2 | // redirect_error.hpp |
3 | // ~~~~~~~~~~~~~~~~~~ |
4 | // |
5 | // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
6 | // |
7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
9 | // |
10 | |
11 | #ifndef BOOST_ASIO_REDIRECT_ERROR_HPP |
12 | #define BOOST_ASIO_REDIRECT_ERROR_HPP |
13 | |
14 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) |
15 | # pragma once |
16 | #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) |
17 | |
18 | #include <boost/asio/detail/config.hpp> |
19 | #include <boost/asio/detail/type_traits.hpp> |
20 | #include <boost/system/error_code.hpp> |
21 | |
22 | #include <boost/asio/detail/push_options.hpp> |
23 | |
24 | namespace boost { |
25 | namespace asio { |
26 | |
27 | /// A @ref completion_token adapter used to specify that an error produced by an |
28 | /// asynchronous operation is captured to an error_code variable. |
29 | /** |
30 | * The redirect_error_t class is used to indicate that any error_code produced |
31 | * by an asynchronous operation is captured to a specified variable. |
32 | */ |
33 | template <typename CompletionToken> |
34 | class redirect_error_t |
35 | { |
36 | public: |
37 | /// Constructor. |
38 | template <typename T> |
39 | redirect_error_t(T&& completion_token, boost::system::error_code& ec) |
40 | : token_(static_cast<T&&>(completion_token)), |
41 | ec_(ec) |
42 | { |
43 | } |
44 | |
45 | //private: |
46 | CompletionToken token_; |
47 | boost::system::error_code& ec_; |
48 | }; |
49 | |
50 | /// Adapt a @ref completion_token to capture error_code values to a variable. |
51 | template <typename CompletionToken> |
52 | inline redirect_error_t<decay_t<CompletionToken>> redirect_error( |
53 | CompletionToken&& completion_token, boost::system::error_code& ec) |
54 | { |
55 | return redirect_error_t<decay_t<CompletionToken>>( |
56 | static_cast<CompletionToken&&>(completion_token), ec); |
57 | } |
58 | |
59 | } // namespace asio |
60 | } // namespace boost |
61 | |
62 | #include <boost/asio/detail/pop_options.hpp> |
63 | |
64 | #include <boost/asio/impl/redirect_error.hpp> |
65 | |
66 | #endif // BOOST_ASIO_REDIRECT_ERROR_HPP |
67 | |