pstl_find.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef _LIBCPP___ALGORITHM_PSTL_FIND_H
  9. #define _LIBCPP___ALGORITHM_PSTL_FIND_H
  10. #include <__algorithm/comp.h>
  11. #include <__algorithm/find.h>
  12. #include <__algorithm/pstl_backend.h>
  13. #include <__algorithm/pstl_frontend_dispatch.h>
  14. #include <__config>
  15. #include <__iterator/cpp17_iterator_concepts.h>
  16. #include <__type_traits/enable_if.h>
  17. #include <__type_traits/is_execution_policy.h>
  18. #include <__type_traits/remove_cvref.h>
  19. #include <__utility/move.h>
  20. #include <__utility/terminate_on_exception.h>
  21. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  22. # pragma GCC system_header
  23. #endif
  24. #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
  25. _LIBCPP_BEGIN_NAMESPACE_STD
  26. template <class _ExecutionPolicy,
  27. class _ForwardIterator,
  28. class _Predicate,
  29. class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
  30. enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
  31. _LIBCPP_HIDE_FROM_ABI _ForwardIterator
  32. find_if(_ExecutionPolicy&&, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
  33. _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
  34. using _Backend = typename __select_backend<_RawPolicy>::type;
  35. return std::__pstl_find_if<_RawPolicy>(_Backend{}, std::move(__first), std::move(__last), std::move(__pred));
  36. }
  37. template <class>
  38. void __pstl_find_if_not();
  39. template <class _ExecutionPolicy,
  40. class _ForwardIterator,
  41. class _Predicate,
  42. class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
  43. enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
  44. _LIBCPP_HIDE_FROM_ABI _ForwardIterator
  45. find_if_not(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
  46. _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
  47. return std::__pstl_frontend_dispatch(
  48. _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find_if_not, _RawPolicy),
  49. [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
  50. return std::find_if(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __value) {
  51. return !__g_pred(__value);
  52. });
  53. },
  54. std::move(__first),
  55. std::move(__last),
  56. std::move(__pred));
  57. }
  58. template <class>
  59. void __pstl_find();
  60. template <class _ExecutionPolicy,
  61. class _ForwardIterator,
  62. class _Tp,
  63. class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
  64. enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
  65. _LIBCPP_HIDE_FROM_ABI _ForwardIterator
  66. find(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
  67. _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
  68. return std::__pstl_frontend_dispatch(
  69. _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_find, _RawPolicy),
  70. [&](_ForwardIterator __g_first, _ForwardIterator __g_last, const _Tp& __g_value) {
  71. return std::find_if(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __element) {
  72. return __element == __g_value;
  73. });
  74. },
  75. std::move(__first),
  76. std::move(__last),
  77. __value);
  78. }
  79. _LIBCPP_END_NAMESPACE_STD
  80. #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
  81. #endif // _LIBCPP___ALGORITHM_PSTL_FIND_H