detached.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // impl/detached.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_IMPL_DETACHED_HPP
  11. #define BOOST_ASIO_IMPL_DETACHED_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/async_result.hpp>
  17. #include <boost/asio/detail/variadic_templates.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace detail {
  22. // Class to adapt a detached_t as a completion handler.
  23. class detached_handler
  24. {
  25. public:
  26. typedef void result_type;
  27. detached_handler(detached_t)
  28. {
  29. }
  30. #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  31. template <typename... Args>
  32. void operator()(Args...)
  33. {
  34. }
  35. #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  36. void operator()()
  37. {
  38. }
  39. #define BOOST_ASIO_PRIVATE_DETACHED_DEF(n) \
  40. template <BOOST_ASIO_VARIADIC_TPARAMS(n)> \
  41. void operator()(BOOST_ASIO_VARIADIC_TARGS(n)) \
  42. { \
  43. } \
  44. /**/
  45. BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_DETACHED_DEF)
  46. #undef BOOST_ASIO_PRIVATE_DETACHED_DEF
  47. #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  48. };
  49. } // namespace detail
  50. #if !defined(GENERATING_DOCUMENTATION)
  51. template <typename Signature>
  52. struct async_result<detached_t, Signature>
  53. {
  54. typedef boost::asio::detail::detached_handler completion_handler_type;
  55. typedef void return_type;
  56. explicit async_result(completion_handler_type&)
  57. {
  58. }
  59. void get()
  60. {
  61. }
  62. #if defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  63. template <typename Initiation, typename RawCompletionToken, typename... Args>
  64. static return_type initiate(
  65. BOOST_ASIO_MOVE_ARG(Initiation) initiation,
  66. BOOST_ASIO_MOVE_ARG(RawCompletionToken),
  67. BOOST_ASIO_MOVE_ARG(Args)... args)
  68. {
  69. BOOST_ASIO_MOVE_CAST(Initiation)(initiation)(
  70. detail::detached_handler(detached_t()),
  71. BOOST_ASIO_MOVE_CAST(Args)(args)...);
  72. }
  73. #else // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  74. template <typename Initiation, typename RawCompletionToken>
  75. static return_type initiate(
  76. BOOST_ASIO_MOVE_ARG(Initiation) initiation,
  77. BOOST_ASIO_MOVE_ARG(RawCompletionToken))
  78. {
  79. BOOST_ASIO_MOVE_CAST(Initiation)(initiation)(
  80. detail::detached_handler(detached_t()));
  81. }
  82. #define BOOST_ASIO_PRIVATE_INITIATE_DEF(n) \
  83. template <typename Initiation, typename RawCompletionToken, \
  84. BOOST_ASIO_VARIADIC_TPARAMS(n)> \
  85. static return_type initiate( \
  86. BOOST_ASIO_MOVE_ARG(Initiation) initiation, \
  87. BOOST_ASIO_MOVE_ARG(RawCompletionToken), \
  88. BOOST_ASIO_VARIADIC_MOVE_PARAMS(n)) \
  89. { \
  90. BOOST_ASIO_MOVE_CAST(Initiation)(initiation)( \
  91. detail::detached_handler(detached_t()), \
  92. BOOST_ASIO_VARIADIC_MOVE_ARGS(n)); \
  93. } \
  94. /**/
  95. BOOST_ASIO_VARIADIC_GENERATE(BOOST_ASIO_PRIVATE_INITIATE_DEF)
  96. #undef BOOST_ASIO_PRIVATE_INITIATE_DEF
  97. #endif // defined(BOOST_ASIO_HAS_VARIADIC_TEMPLATES)
  98. };
  99. #endif // !defined(GENERATING_DOCUMENTATION)
  100. } // namespace asio
  101. } // namespace boost
  102. #include <boost/asio/detail/pop_options.hpp>
  103. #endif // BOOST_ASIO_IMPL_DETACHED_HPP