handler_invoke_helpers.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // detail/handler_invoke_helpers.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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_DETAIL_HANDLER_INVOKE_HELPERS_HPP
  11. #define BOOST_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 <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/memory.hpp>
  17. #include <boost/asio/handler_invoke_hook.hpp>
  18. #include <boost/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 boost_asio_handler_invoke_helpers
  21. // namespace is defined here for that purpose.
  22. namespace boost_asio_handler_invoke_helpers {
  23. #if defined(BOOST_ASIO_NO_DEPRECATED)
  24. template <typename Function, typename Context>
  25. inline void error_if_hook_is_defined(Function& function, Context& context)
  26. {
  27. using boost::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<boost::asio::asio_handler_invoke_is_no_longer_used>(
  31. asio_handler_invoke(function, boost::asio::detail::addressof(context)));
  32. }
  33. #endif // defined(BOOST_ASIO_NO_DEPRECATED)
  34. template <typename Function, typename Context>
  35. inline void invoke(Function& function, Context& context)
  36. {
  37. #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
  38. Function tmp(function);
  39. tmp();
  40. #elif defined(BOOST_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 boost::asio::asio_handler_invoke;
  47. asio_handler_invoke(function, boost::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(BOOST_ASIO_HAS_HANDLER_HOOKS)
  54. Function tmp(function);
  55. tmp();
  56. #elif defined(BOOST_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 boost::asio::asio_handler_invoke;
  64. asio_handler_invoke(function, boost::asio::detail::addressof(context));
  65. #endif
  66. }
  67. } // namespace boost_asio_handler_invoke_helpers
  68. #include <boost/asio/detail/pop_options.hpp>
  69. #endif // BOOST_ASIO_DETAIL_HANDLER_INVOKE_HELPERS_HPP