async_result.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // async_result.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 ARCHETYPES_ASYNC_RESULT_HPP
  11. #define ARCHETYPES_ASYNC_RESULT_HPP
  12. #include <boost/asio/async_result.hpp>
  13. namespace archetypes {
  14. struct lazy_handler
  15. {
  16. };
  17. template <typename Signature>
  18. struct concrete_handler;
  19. template <typename R, typename Arg1>
  20. struct concrete_handler<R(Arg1)>
  21. {
  22. concrete_handler(lazy_handler)
  23. {
  24. }
  25. void operator()(typename boost::asio::decay<Arg1>::type)
  26. {
  27. }
  28. #if defined(BOOST_ASIO_HAS_MOVE)
  29. concrete_handler(concrete_handler&&) {}
  30. private:
  31. concrete_handler(const concrete_handler&);
  32. #endif // defined(BOOST_ASIO_HAS_MOVE)
  33. };
  34. template <typename R, typename Arg1, typename Arg2>
  35. struct concrete_handler<R(Arg1, Arg2)>
  36. {
  37. concrete_handler(lazy_handler)
  38. {
  39. }
  40. void operator()(typename boost::asio::decay<Arg1>::type, typename boost::asio::decay<Arg2>::type)
  41. {
  42. }
  43. #if defined(BOOST_ASIO_HAS_MOVE)
  44. concrete_handler(concrete_handler&&) {}
  45. private:
  46. concrete_handler(const concrete_handler&);
  47. #endif // defined(BOOST_ASIO_HAS_MOVE)
  48. };
  49. } // namespace archetypes
  50. namespace boost {
  51. namespace asio {
  52. template <typename Signature>
  53. class async_result<archetypes::lazy_handler, Signature>
  54. {
  55. public:
  56. // The concrete completion handler type.
  57. typedef archetypes::concrete_handler<Signature> completion_handler_type;
  58. // The return type of the initiating function.
  59. typedef int return_type;
  60. // Construct an async_result from a given handler.
  61. explicit async_result(completion_handler_type&)
  62. {
  63. }
  64. // Obtain the value to be returned from the initiating function.
  65. return_type get()
  66. {
  67. return 42;
  68. }
  69. private:
  70. // Disallow copying and assignment.
  71. async_result(const async_result&) BOOST_ASIO_DELETED;
  72. async_result& operator=(const async_result&) BOOST_ASIO_DELETED;
  73. };
  74. } // namespace asio
  75. } // namespace boost
  76. #endif // ARCHETYPES_ASYNC_RESULT_HPP