redirect_error.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // experimental/redirect_error.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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. #ifndef BOOST_ASIO_EXPERIMENTAL_REDIRECT_ERROR_HPP
  11. #define BOOST_ASIO_EXPERIMENTAL_REDIRECT_ERROR_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/type_traits.hpp>
  17. #include <boost/system/error_code.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace experimental {
  22. /// Completion token type used to specify that an error produced by an
  23. /// asynchronous operation is captured to an error_code variable.
  24. /**
  25. * The redirect_error_t class is used to indicate that any error_code produced
  26. * by an asynchronous operation is captured to a specified variable.
  27. */
  28. template <typename CompletionToken>
  29. class redirect_error_t
  30. {
  31. public:
  32. /// Constructor.
  33. template <typename T>
  34. redirect_error_t(BOOST_ASIO_MOVE_ARG(T) completion_token,
  35. boost::system::error_code& ec)
  36. : token_(BOOST_ASIO_MOVE_CAST(T)(completion_token)),
  37. ec_(ec)
  38. {
  39. }
  40. //private:
  41. CompletionToken token_;
  42. boost::system::error_code& ec_;
  43. };
  44. /// Create a completion token to capture error_code values to a variable.
  45. template <typename CompletionToken>
  46. inline redirect_error_t<typename decay<CompletionToken>::type> redirect_error(
  47. CompletionToken&& completion_token, boost::system::error_code& ec)
  48. {
  49. return redirect_error_t<typename decay<CompletionToken>::type>(
  50. BOOST_ASIO_MOVE_CAST(CompletionToken)(completion_token), ec);
  51. }
  52. } // namespace experimental
  53. } // namespace asio
  54. } // namespace boost
  55. #include <boost/asio/detail/pop_options.hpp>
  56. #include <boost/asio/experimental/impl/redirect_error.hpp>
  57. #endif // BOOST_ASIO_EXPERIMENTAL_REDIRECT_ERROR_HPP