executor.hpp 3.0 KB

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