]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | // |
92f5a8d4 TL |
2 | // redirect_error.hpp |
3 | // ~~~~~~~~~~~~~~~~~~ | |
11fdf7f2 | 4 | // |
f67539c2 | 5 | // Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
11fdf7f2 TL |
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 | ||
92f5a8d4 TL |
11 | #ifndef BOOST_ASIO_REDIRECT_ERROR_HPP |
12 | #define BOOST_ASIO_REDIRECT_ERROR_HPP | |
11fdf7f2 TL |
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 { | |
11fdf7f2 TL |
26 | |
27 | /// Completion token type 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(BOOST_ASIO_MOVE_ARG(T) completion_token, | |
40 | boost::system::error_code& ec) | |
41 | : token_(BOOST_ASIO_MOVE_CAST(T)(completion_token)), | |
42 | ec_(ec) | |
43 | { | |
44 | } | |
45 | ||
46 | //private: | |
47 | CompletionToken token_; | |
48 | boost::system::error_code& ec_; | |
49 | }; | |
50 | ||
51 | /// Create a completion token to capture error_code values to a variable. | |
52 | template <typename CompletionToken> | |
53 | inline redirect_error_t<typename decay<CompletionToken>::type> redirect_error( | |
92f5a8d4 TL |
54 | BOOST_ASIO_MOVE_ARG(CompletionToken) completion_token, |
55 | boost::system::error_code& ec) | |
11fdf7f2 TL |
56 | { |
57 | return redirect_error_t<typename decay<CompletionToken>::type>( | |
58 | BOOST_ASIO_MOVE_CAST(CompletionToken)(completion_token), ec); | |
59 | } | |
60 | ||
11fdf7f2 TL |
61 | } // namespace asio |
62 | } // namespace boost | |
63 | ||
64 | #include <boost/asio/detail/pop_options.hpp> | |
65 | ||
92f5a8d4 | 66 | #include <boost/asio/impl/redirect_error.hpp> |
11fdf7f2 | 67 | |
92f5a8d4 | 68 | #endif // BOOST_ASIO_REDIRECT_ERROR_HPP |