execution_defs.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // -*- C++ -*-
  2. //===-- execution_defs.h --------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef __PSTL_execution_policy_defs_H
  10. #define __PSTL_execution_policy_defs_H
  11. #include <type_traits>
  12. namespace __pstl
  13. {
  14. namespace execution
  15. {
  16. inline namespace v1
  17. {
  18. // 2.4, Sequential execution policy
  19. class sequenced_policy
  20. {
  21. public:
  22. // For internal use only
  23. static constexpr std::false_type
  24. __allow_unsequenced()
  25. {
  26. return std::false_type{};
  27. }
  28. static constexpr std::false_type
  29. __allow_vector()
  30. {
  31. return std::false_type{};
  32. }
  33. static constexpr std::false_type
  34. __allow_parallel()
  35. {
  36. return std::false_type{};
  37. }
  38. };
  39. #if __PSTL_USE_PAR_POLICIES
  40. // 2.5, Parallel execution policy
  41. class parallel_policy
  42. {
  43. public:
  44. // For internal use only
  45. static constexpr std::false_type
  46. __allow_unsequenced()
  47. {
  48. return std::false_type{};
  49. }
  50. static constexpr std::false_type
  51. __allow_vector()
  52. {
  53. return std::false_type{};
  54. }
  55. static constexpr std::true_type
  56. __allow_parallel()
  57. {
  58. return std::true_type{};
  59. }
  60. };
  61. // 2.6, Parallel+Vector execution policy
  62. class parallel_unsequenced_policy
  63. {
  64. public:
  65. // For internal use only
  66. static constexpr std::true_type
  67. __allow_unsequenced()
  68. {
  69. return std::true_type{};
  70. }
  71. static constexpr std::true_type
  72. __allow_vector()
  73. {
  74. return std::true_type{};
  75. }
  76. static constexpr std::true_type
  77. __allow_parallel()
  78. {
  79. return std::true_type{};
  80. }
  81. };
  82. #endif
  83. class unsequenced_policy
  84. {
  85. public:
  86. // For internal use only
  87. static constexpr std::true_type
  88. __allow_unsequenced()
  89. {
  90. return std::true_type{};
  91. }
  92. static constexpr std::true_type
  93. __allow_vector()
  94. {
  95. return std::true_type{};
  96. }
  97. static constexpr std::false_type
  98. __allow_parallel()
  99. {
  100. return std::false_type{};
  101. }
  102. };
  103. // 2.8, Execution policy objects
  104. constexpr sequenced_policy seq{};
  105. #if __PSTL_USE_PAR_POLICIES
  106. constexpr parallel_policy par{};
  107. constexpr parallel_unsequenced_policy par_unseq{};
  108. #endif
  109. constexpr unsequenced_policy unseq{};
  110. // 2.3, Execution policy type trait
  111. template <class _Tp>
  112. struct is_execution_policy : std::false_type
  113. {
  114. };
  115. template <>
  116. struct is_execution_policy<__pstl::execution::sequenced_policy> : std::true_type
  117. {
  118. };
  119. #if __PSTL_USE_PAR_POLICIES
  120. template <>
  121. struct is_execution_policy<__pstl::execution::parallel_policy> : std::true_type
  122. {
  123. };
  124. template <>
  125. struct is_execution_policy<__pstl::execution::parallel_unsequenced_policy> : std::true_type
  126. {
  127. };
  128. #endif
  129. template <>
  130. struct is_execution_policy<__pstl::execution::unsequenced_policy> : std::true_type
  131. {
  132. };
  133. #if __PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT
  134. template <class _Tp>
  135. constexpr bool is_execution_policy_v = __pstl::execution::is_execution_policy<_Tp>::value;
  136. #endif
  137. } // namespace v1
  138. } // namespace execution
  139. namespace __internal
  140. {
  141. template <class _ExecPolicy, class _Tp>
  142. using __enable_if_execution_policy =
  143. typename std::enable_if<__pstl::execution::is_execution_policy<typename std::decay<_ExecPolicy>::type>::value,
  144. _Tp>::type;
  145. } // namespace __internal
  146. } // namespace __pstl
  147. #endif /* __PSTL_execution_policy_defs_H */