• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
9 #ifndef _LIBCPP___ALGORITHM_PSTL_ANY_ALL_NONE_OF_H
10 #define _LIBCPP___ALGORITHM_PSTL_ANY_ALL_NONE_OF_H
11 
12 #include <__algorithm/pstl_find.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 <optional>
21 
22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23 #  pragma GCC system_header
24 #endif
25 
26 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
27 
28 _LIBCPP_BEGIN_NAMESPACE_STD
29 
30 template <class>
31 void __pstl_any_of(); // declaration needed for the frontend dispatch below
32 
33 template <class _ExecutionPolicy,
34           class _ForwardIterator,
35           class _Predicate,
36           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
37           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
__any_of(_ExecutionPolicy && __policy,_ForwardIterator && __first,_ForwardIterator && __last,_Predicate && __pred)38 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool> __any_of(
39     _ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Predicate&& __pred) noexcept {
40   return std::__pstl_frontend_dispatch(
41       _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_any_of, _RawPolicy),
42       [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) -> optional<bool> {
43         auto __res = std::__find_if(__policy, __g_first, __g_last, __g_pred);
44         if (!__res)
45           return nullopt;
46         return *__res != __g_last;
47       },
48       std::move(__first),
49       std::move(__last),
50       std::move(__pred));
51 }
52 
53 template <class _ExecutionPolicy,
54           class _ForwardIterator,
55           class _Predicate,
56           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
57           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
58 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
any_of(_ExecutionPolicy && __policy,_ForwardIterator __first,_ForwardIterator __last,_Predicate __pred)59 any_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
60   _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
61   auto __res = std::__any_of(__policy, std::move(__first), std::move(__last), std::move(__pred));
62   if (!__res)
63     std::__throw_bad_alloc();
64   return *std::move(__res);
65 }
66 
67 template <class>
68 void __pstl_all_of(); // declaration needed for the frontend dispatch below
69 
70 template <class _ExecutionPolicy,
71           class _ForwardIterator,
72           class _Pred,
73           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
74           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
75 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
__all_of(_ExecutionPolicy && __policy,_ForwardIterator && __first,_ForwardIterator && __last,_Pred && __pred)76 __all_of(_ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Pred&& __pred) noexcept {
77   return std::__pstl_frontend_dispatch(
78       _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_all_of, _RawPolicy),
79       [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) -> optional<bool> {
80         auto __res = std::__any_of(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __value) {
81           return !__g_pred(__value);
82         });
83         if (!__res)
84           return nullopt;
85         return !*__res;
86       },
87       std::move(__first),
88       std::move(__last),
89       std::move(__pred));
90 }
91 
92 template <class _ExecutionPolicy,
93           class _ForwardIterator,
94           class _Pred,
95           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
96           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
97 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
all_of(_ExecutionPolicy && __policy,_ForwardIterator __first,_ForwardIterator __last,_Pred __pred)98 all_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
99   _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
100   auto __res = std::__all_of(__policy, std::move(__first), std::move(__last), std::move(__pred));
101   if (!__res)
102     std::__throw_bad_alloc();
103   return *std::move(__res);
104 }
105 
106 template <class>
107 void __pstl_none_of(); // declaration needed for the frontend dispatch below
108 
109 template <class _ExecutionPolicy,
110           class _ForwardIterator,
111           class _Pred,
112           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
113           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
114 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool>
__none_of(_ExecutionPolicy && __policy,_ForwardIterator && __first,_ForwardIterator && __last,_Pred && __pred)115 __none_of(_ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Pred&& __pred) noexcept {
116   return std::__pstl_frontend_dispatch(
117       _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_none_of, _RawPolicy),
118       [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) -> optional<bool> {
119         auto __res = std::__any_of(__policy, __g_first, __g_last, __g_pred);
120         if (!__res)
121           return nullopt;
122         return !*__res;
123       },
124       std::move(__first),
125       std::move(__last),
126       std::move(__pred));
127 }
128 
129 template <class _ExecutionPolicy,
130           class _ForwardIterator,
131           class _Pred,
132           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
133           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
134 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
none_of(_ExecutionPolicy && __policy,_ForwardIterator __first,_ForwardIterator __last,_Pred __pred)135 none_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
136   _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
137   auto __res = std::__none_of(__policy, std::move(__first), std::move(__last), std::move(__pred));
138   if (!__res)
139     std::__throw_bad_alloc();
140   return *std::move(__res);
141 }
142 
143 _LIBCPP_END_NAMESPACE_STD
144 
145 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
146 
147 #endif // _LIBCPP___ALGORITHM_PSTL_ANY_ALL_NONE_OF_H
148