deferred.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // experimental/impl/deferred.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2022 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_EXPERIMENTAL_IMPL_DEFERRED_HPP
  11. #define ASIO_EXPERIMENTAL_IMPL_DEFERRED_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/push_options.hpp"
  16. namespace asio {
  17. #if !defined(GENERATING_DOCUMENTATION)
  18. template <typename R, typename... Args>
  19. class async_result<
  20. experimental::detail::deferred_signature_probe, R(Args...)>
  21. {
  22. public:
  23. typedef experimental::detail::deferred_signature_probe_result<void(Args...)>
  24. return_type;
  25. template <typename Initiation, typename... InitArgs>
  26. static return_type initiate(
  27. ASIO_MOVE_ARG(Initiation),
  28. experimental::detail::deferred_signature_probe,
  29. ASIO_MOVE_ARG(InitArgs)...)
  30. {
  31. return return_type{};
  32. }
  33. };
  34. template <typename Signature>
  35. class async_result<experimental::deferred_t, Signature>
  36. {
  37. public:
  38. template <typename Initiation, typename... InitArgs>
  39. static experimental::deferred_async_operation<
  40. Signature, Initiation, InitArgs...>
  41. initiate(ASIO_MOVE_ARG(Initiation) initiation,
  42. experimental::deferred_t, ASIO_MOVE_ARG(InitArgs)... args)
  43. {
  44. return experimental::deferred_async_operation<
  45. Signature, Initiation, InitArgs...>(
  46. experimental::deferred_init_tag{},
  47. ASIO_MOVE_CAST(Initiation)(initiation),
  48. ASIO_MOVE_CAST(InitArgs)(args)...);
  49. }
  50. };
  51. template <typename Function, typename R, typename... Args>
  52. class async_result<
  53. experimental::deferred_function<Function>, R(Args...)>
  54. {
  55. public:
  56. template <typename Initiation, typename... InitArgs>
  57. static auto initiate(ASIO_MOVE_ARG(Initiation) initiation,
  58. experimental::deferred_function<Function> token,
  59. ASIO_MOVE_ARG(InitArgs)... init_args)
  60. {
  61. return experimental::deferred_sequence<
  62. experimental::deferred_async_operation<
  63. R(Args...), Initiation, InitArgs...>,
  64. Function>(experimental::deferred_init_tag{},
  65. experimental::deferred_async_operation<
  66. R(Args...), Initiation, InitArgs...>(
  67. experimental::deferred_init_tag{},
  68. ASIO_MOVE_CAST(Initiation)(initiation),
  69. ASIO_MOVE_CAST(InitArgs)(init_args)...),
  70. ASIO_MOVE_CAST(Function)(token.function_));
  71. }
  72. };
  73. template <template <typename, typename> class Associator,
  74. typename Handler, typename Tail, typename DefaultCandidate>
  75. struct associator<Associator,
  76. experimental::detail::deferred_sequence_handler<Handler, Tail>,
  77. DefaultCandidate>
  78. : Associator<Handler, DefaultCandidate>
  79. {
  80. static typename Associator<Handler, DefaultCandidate>::type get(
  81. const experimental::detail::deferred_sequence_handler<Handler, Tail>& h,
  82. const DefaultCandidate& c = DefaultCandidate()) ASIO_NOEXCEPT
  83. {
  84. return Associator<Handler, DefaultCandidate>::get(h.handler_, c);
  85. }
  86. };
  87. #endif // !defined(GENERATING_DOCUMENTATION)
  88. } // namespace asio
  89. #include "asio/detail/pop_options.hpp"
  90. #endif // ASIO_EXPERIMENTAL_IMPL_DEFERRED_HPP