handler_invoke_helpers.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //
  2. // detail/handler_invoke_helpers.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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. template <typename Function, typename Context>
  24. inline void invoke(Function& function, Context& context)
  25. {
  26. #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
  27. Function tmp(function);
  28. tmp();
  29. #else
  30. using boost::asio::asio_handler_invoke;
  31. asio_handler_invoke(function, boost::asio::detail::addressof(context));
  32. #endif
  33. }
  34. template <typename Function, typename Context>
  35. inline void invoke(const Function& function, Context& context)
  36. {
  37. #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
  38. Function tmp(function);
  39. tmp();
  40. #else
  41. using boost::asio::asio_handler_invoke;
  42. asio_handler_invoke(function, boost::asio::detail::addressof(context));
  43. #endif
  44. }
  45. } // namespace boost_asio_handler_invoke_helpers
  46. #include <boost/asio/detail/pop_options.hpp>
  47. #endif // BOOST_ASIO_DETAIL_HANDLER_INVOKE_HELPERS_HPP