handler_invoke_helpers.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // detail/handler_invoke_helpers.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_DETAIL_HANDLER_INVOKE_HELPERS_HPP
  11. #define ASIO_DETAIL_HANDLER_INVOKE_HELPERS_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/detail/memory.hpp"
  17. #include "asio/handler_invoke_hook.hpp"
  18. #include "asio/detail/push_options.hpp"
  19. // Calls to asio_handler_invoke must be made from a namespace that does not
  20. // contain overloads of this function. The asio_handler_invoke_helpers
  21. // namespace is defined here for that purpose.
  22. namespace asio_handler_invoke_helpers {
  23. #if defined(ASIO_NO_DEPRECATED)
  24. template <typename Function, typename Context>
  25. inline void error_if_hook_is_defined(Function& function, Context& context)
  26. {
  27. using asio::asio_handler_invoke;
  28. // If you get an error here it is because some of your handlers still
  29. // overload asio_handler_invoke, but this hook is no longer used.
  30. (void)static_cast<asio::asio_handler_invoke_is_no_longer_used>(
  31. asio_handler_invoke(function, asio::detail::addressof(context)));
  32. }
  33. #endif // defined(ASIO_NO_DEPRECATED)
  34. template <typename Function, typename Context>
  35. inline void invoke(Function& function, Context& context)
  36. {
  37. #if !defined(ASIO_HAS_HANDLER_HOOKS)
  38. Function tmp(function);
  39. tmp();
  40. #elif defined(ASIO_NO_DEPRECATED)
  41. // The asio_handler_invoke hook is no longer used to invoke the function.
  42. (void)&error_if_hook_is_defined<Function, Context>;
  43. (void)context;
  44. function();
  45. #else
  46. using asio::asio_handler_invoke;
  47. asio_handler_invoke(function, asio::detail::addressof(context));
  48. #endif
  49. }
  50. template <typename Function, typename Context>
  51. inline void invoke(const Function& function, Context& context)
  52. {
  53. #if !defined(ASIO_HAS_HANDLER_HOOKS)
  54. Function tmp(function);
  55. tmp();
  56. #elif defined(ASIO_NO_DEPRECATED)
  57. // The asio_handler_invoke hook is no longer used to invoke the function.
  58. (void)&error_if_hook_is_defined<const Function, Context>;
  59. (void)context;
  60. Function tmp(function);
  61. tmp();
  62. #else
  63. using asio::asio_handler_invoke;
  64. asio_handler_invoke(function, asio::detail::addressof(context));
  65. #endif
  66. }
  67. } // namespace asio_handler_invoke_helpers
  68. #include "asio/detail/pop_options.hpp"
  69. #endif // ASIO_DETAIL_HANDLER_INVOKE_HELPERS_HPP