redirect_error.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // redirect_error.hpp
  3. // ~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_REDIRECT_ERROR_HPP
  11. #define BOOST_ASIO_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. /// Completion token type used to specify that an error produced by an
  22. /// asynchronous operation is captured to an error_code variable.
  23. /**
  24. * The redirect_error_t class is used to indicate that any error_code produced
  25. * by an asynchronous operation is captured to a specified variable.
  26. */
  27. template <typename CompletionToken>
  28. class redirect_error_t
  29. {
  30. public:
  31. /// Constructor.
  32. template <typename T>
  33. redirect_error_t(BOOST_ASIO_MOVE_ARG(T) completion_token,
  34. boost::system::error_code& ec)
  35. : token_(BOOST_ASIO_MOVE_CAST(T)(completion_token)),
  36. ec_(ec)
  37. {
  38. }
  39. //private:
  40. CompletionToken token_;
  41. boost::system::error_code& ec_;
  42. };
  43. /// Create a completion token to capture error_code values to a variable.
  44. template <typename CompletionToken>
  45. inline redirect_error_t<typename decay<CompletionToken>::type> redirect_error(
  46. BOOST_ASIO_MOVE_ARG(CompletionToken) completion_token,
  47. 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 asio
  53. } // namespace boost
  54. #include <boost/asio/detail/pop_options.hpp>
  55. #include <boost/asio/impl/redirect_error.hpp>
  56. #endif // BOOST_ASIO_REDIRECT_ERROR_HPP