detached.hpp 1.6 KB

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