is_executor.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // detail/is_executor.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_IS_EXECUTOR_HPP
  11. #define BOOST_ASIO_DETAIL_IS_EXECUTOR_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/type_traits.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace detail {
  21. struct executor_memfns_base
  22. {
  23. void context();
  24. void on_work_started();
  25. void on_work_finished();
  26. void dispatch();
  27. void post();
  28. void defer();
  29. };
  30. template <typename T>
  31. struct executor_memfns_derived
  32. : T, executor_memfns_base
  33. {
  34. };
  35. template <typename T, T>
  36. struct executor_memfns_check
  37. {
  38. };
  39. template <typename>
  40. char (&context_memfn_helper(...))[2];
  41. template <typename T>
  42. char context_memfn_helper(
  43. executor_memfns_check<
  44. void (executor_memfns_base::*)(),
  45. &executor_memfns_derived<T>::context>*);
  46. template <typename>
  47. char (&on_work_started_memfn_helper(...))[2];
  48. template <typename T>
  49. char on_work_started_memfn_helper(
  50. executor_memfns_check<
  51. void (executor_memfns_base::*)(),
  52. &executor_memfns_derived<T>::on_work_started>*);
  53. template <typename>
  54. char (&on_work_finished_memfn_helper(...))[2];
  55. template <typename T>
  56. char on_work_finished_memfn_helper(
  57. executor_memfns_check<
  58. void (executor_memfns_base::*)(),
  59. &executor_memfns_derived<T>::on_work_finished>*);
  60. template <typename>
  61. char (&dispatch_memfn_helper(...))[2];
  62. template <typename T>
  63. char dispatch_memfn_helper(
  64. executor_memfns_check<
  65. void (executor_memfns_base::*)(),
  66. &executor_memfns_derived<T>::dispatch>*);
  67. template <typename>
  68. char (&post_memfn_helper(...))[2];
  69. template <typename T>
  70. char post_memfn_helper(
  71. executor_memfns_check<
  72. void (executor_memfns_base::*)(),
  73. &executor_memfns_derived<T>::post>*);
  74. template <typename>
  75. char (&defer_memfn_helper(...))[2];
  76. template <typename T>
  77. char defer_memfn_helper(
  78. executor_memfns_check<
  79. void (executor_memfns_base::*)(),
  80. &executor_memfns_derived<T>::defer>*);
  81. template <typename T>
  82. struct is_executor_class
  83. : integral_constant<bool,
  84. sizeof(context_memfn_helper<T>(0)) != 1 &&
  85. sizeof(on_work_started_memfn_helper<T>(0)) != 1 &&
  86. sizeof(on_work_finished_memfn_helper<T>(0)) != 1 &&
  87. sizeof(dispatch_memfn_helper<T>(0)) != 1 &&
  88. sizeof(post_memfn_helper<T>(0)) != 1 &&
  89. sizeof(defer_memfn_helper<T>(0)) != 1>
  90. {
  91. };
  92. template <typename T>
  93. struct is_executor
  94. : conditional<is_class<T>::value,
  95. is_executor_class<T>,
  96. false_type>::type
  97. {
  98. };
  99. } // namespace detail
  100. } // namespace asio
  101. } // namespace boost
  102. #include <boost/asio/detail/pop_options.hpp>
  103. #endif // BOOST_ASIO_DETAIL_IS_EXECUTOR_HPP