async_result.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // async_result.hpp
  3. // ~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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 ASIO_ASYNC_RESULT_HPP
  11. #define ASIO_ASYNC_RESULT_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/handler_type.hpp"
  17. #include "asio/detail/push_options.hpp"
  18. namespace asio {
  19. /// An interface for customising the behaviour of an initiating function.
  20. /**
  21. * This template may be specialised for user-defined handler types.
  22. */
  23. template <typename Handler>
  24. class async_result
  25. {
  26. public:
  27. /// The return type of the initiating function.
  28. typedef void type;
  29. /// Construct an async result from a given handler.
  30. /**
  31. * When using a specalised async_result, the constructor has an opportunity
  32. * to initialise some state associated with the handler, which is then
  33. * returned from the initiating function.
  34. */
  35. explicit async_result(Handler&)
  36. {
  37. }
  38. /// Obtain the value to be returned from the initiating function.
  39. type get()
  40. {
  41. }
  42. };
  43. namespace detail {
  44. // Helper template to deduce the true type of a handler, capture a local copy
  45. // of the handler, and then create an async_result for the handler.
  46. template <typename Handler, typename Signature>
  47. struct async_result_init
  48. {
  49. explicit async_result_init(ASIO_MOVE_ARG(Handler) orig_handler)
  50. : handler(ASIO_MOVE_CAST(Handler)(orig_handler)),
  51. result(handler)
  52. {
  53. }
  54. typename handler_type<Handler, Signature>::type handler;
  55. async_result<typename handler_type<Handler, Signature>::type> result;
  56. };
  57. template <typename Handler, typename Signature>
  58. struct async_result_type_helper
  59. {
  60. typedef typename async_result<
  61. typename handler_type<Handler, Signature>::type
  62. >::type type;
  63. };
  64. } // namespace detail
  65. } // namespace asio
  66. #include "asio/detail/pop_options.hpp"
  67. #if defined(GENERATING_DOCUMENTATION)
  68. # define ASIO_INITFN_RESULT_TYPE(h, sig) \
  69. void_or_deduced
  70. #elif defined(_MSC_VER) && (_MSC_VER < 1500)
  71. # define ASIO_INITFN_RESULT_TYPE(h, sig) \
  72. typename ::asio::detail::async_result_type_helper<h, sig>::type
  73. #else
  74. # define ASIO_INITFN_RESULT_TYPE(h, sig) \
  75. typename ::asio::async_result< \
  76. typename ::asio::handler_type<h, sig>::type>::type
  77. #endif
  78. #endif // ASIO_ASYNC_RESULT_HPP