detached.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // impl/detached.hpp
  3. // ~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace detail {
  21. // Class to adapt a detached_t as a completion handler.
  22. class detached_handler
  23. {
  24. public:
  25. typedef void result_type;
  26. detached_handler(detached_t)
  27. {
  28. }
  29. template <typename... Args>
  30. void operator()(Args...)
  31. {
  32. }
  33. };
  34. } // namespace detail
  35. #if !defined(GENERATING_DOCUMENTATION)
  36. template <typename Signature>
  37. struct async_result<detached_t, Signature>
  38. {
  39. typedef boost::asio::detail::detached_handler completion_handler_type;
  40. typedef void return_type;
  41. explicit async_result(completion_handler_type&)
  42. {
  43. }
  44. void get()
  45. {
  46. }
  47. template <typename Initiation, typename RawCompletionToken, typename... Args>
  48. static return_type initiate(Initiation&& initiation,
  49. RawCompletionToken&&, Args&&... args)
  50. {
  51. static_cast<Initiation&&>(initiation)(
  52. detail::detached_handler(detached_t()),
  53. static_cast<Args&&>(args)...);
  54. }
  55. };
  56. #endif // !defined(GENERATING_DOCUMENTATION)
  57. } // namespace asio
  58. } // namespace boost
  59. #include <boost/asio/detail/pop_options.hpp>
  60. #endif // BOOST_ASIO_IMPL_DETACHED_HPP