executor.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // execution/executor.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2024 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_EXECUTION_EXECUTOR_HPP
  11. #define BOOST_ASIO_EXECUTION_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/execution/invocable_archetype.hpp>
  18. #include <boost/asio/traits/equality_comparable.hpp>
  19. #include <boost/asio/traits/execute_member.hpp>
  20. #if defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT) \
  21. && defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  22. # define BOOST_ASIO_HAS_DEDUCED_EXECUTION_IS_EXECUTOR_TRAIT 1
  23. #endif // defined(BOOST_ASIO_HAS_DEDUCED_EXECUTE_MEMBER_TRAIT)
  24. // && defined(BOOST_ASIO_HAS_DEDUCED_EQUALITY_COMPARABLE_TRAIT)
  25. #include <boost/asio/detail/push_options.hpp>
  26. namespace boost {
  27. namespace asio {
  28. namespace execution {
  29. namespace detail {
  30. template <typename T, typename F,
  31. typename = void, typename = void, typename = void, typename = void,
  32. typename = void, typename = void, typename = void, typename = void>
  33. struct is_executor_of_impl : false_type
  34. {
  35. };
  36. template <typename T, typename F>
  37. struct is_executor_of_impl<T, F,
  38. enable_if_t<
  39. traits::execute_member<add_const_t<T>, F>::is_valid
  40. >,
  41. void_t<
  42. result_of_t<decay_t<F>&()>
  43. >,
  44. enable_if_t<
  45. is_constructible<decay_t<F>, F>::value
  46. >,
  47. enable_if_t<
  48. is_move_constructible<decay_t<F>>::value
  49. >,
  50. enable_if_t<
  51. is_nothrow_copy_constructible<T>::value
  52. >,
  53. enable_if_t<
  54. is_nothrow_destructible<T>::value
  55. >,
  56. enable_if_t<
  57. traits::equality_comparable<T>::is_valid
  58. >,
  59. enable_if_t<
  60. traits::equality_comparable<T>::is_noexcept
  61. >> : true_type
  62. {
  63. };
  64. } // namespace detail
  65. /// The is_executor trait detects whether a type T satisfies the
  66. /// execution::executor concept.
  67. /**
  68. * Class template @c is_executor is a UnaryTypeTrait that is derived from @c
  69. * true_type if the type @c T meets the concept definition for an executor,
  70. * otherwise @c false_type.
  71. */
  72. template <typename T>
  73. struct is_executor :
  74. #if defined(GENERATING_DOCUMENTATION)
  75. integral_constant<bool, automatically_determined>
  76. #else // defined(GENERATING_DOCUMENTATION)
  77. detail::is_executor_of_impl<T, invocable_archetype>
  78. #endif // defined(GENERATING_DOCUMENTATION)
  79. {
  80. };
  81. #if defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  82. template <typename T>
  83. constexpr const bool is_executor_v = is_executor<T>::value;
  84. #endif // defined(BOOST_ASIO_HAS_VARIABLE_TEMPLATES)
  85. #if defined(BOOST_ASIO_HAS_CONCEPTS)
  86. template <typename T>
  87. BOOST_ASIO_CONCEPT executor = is_executor<T>::value;
  88. #define BOOST_ASIO_EXECUTION_EXECUTOR ::boost::asio::execution::executor
  89. #else // defined(BOOST_ASIO_HAS_CONCEPTS)
  90. #define BOOST_ASIO_EXECUTION_EXECUTOR typename
  91. #endif // defined(BOOST_ASIO_HAS_CONCEPTS)
  92. } // namespace execution
  93. } // namespace asio
  94. } // namespace boost
  95. #include <boost/asio/detail/pop_options.hpp>
  96. #endif // BOOST_ASIO_EXECUTION_EXECUTOR_HPP