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 <__iterator/iterator_traits.h>
17 #include <__type_traits/enable_if.h>
18 #include <__type_traits/is_execution_policy.h>
19 #include <__type_traits/remove_cvref.h>
20 #include <__utility/move.h>
21 #include <__utility/terminate_on_exception.h>
22 
23 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24 #  pragma GCC system_header
25 #endif
26 
27 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
28 
29 _LIBCPP_BEGIN_NAMESPACE_STD
30 
31 template <class>
32 void __pstl_any_of(); // declaration needed for the frontend dispatch below
33 
34 template <class _ExecutionPolicy,
35           class _ForwardIterator,
36           class _Predicate,
37           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
38           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
39 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
40 any_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
41   _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
42   return std::__pstl_frontend_dispatch(
43       _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_any_of),
44       [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
45         return std::find_if(__policy, __g_first, __g_last, __g_pred) != __g_last;
46       },
47       std::move(__first),
48       std::move(__last),
49       std::move(__pred));
50 }
51 
52 template <class>
53 void __pstl_all_of(); // declaration needed for the frontend dispatch below
54 
55 template <class _ExecutionPolicy,
56           class _ForwardIterator,
57           class _Pred,
58           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
59           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
60 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
61 all_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
62   _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
63   return std::__pstl_frontend_dispatch(
64       _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_all_of),
65       [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) {
66         return !std::any_of(__policy, __g_first, __g_last, [&](__iter_reference<_ForwardIterator> __value) {
67           return !__g_pred(__value);
68         });
69       },
70       std::move(__first),
71       std::move(__last),
72       std::move(__pred));
73 }
74 
75 template <class>
76 void __pstl_none_of(); // declaration needed for the frontend dispatch below
77 
78 template <class _ExecutionPolicy,
79           class _ForwardIterator,
80           class _Pred,
81           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
82           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
83 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
84 none_of(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred) {
85   _LIBCPP_REQUIRE_CPP17_FORWARD_ITERATOR(_ForwardIterator);
86   return std::__pstl_frontend_dispatch(
87       _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_none_of),
88       [&](_ForwardIterator __g_first, _ForwardIterator __g_last, _Pred __g_pred) {
89         return !std::any_of(__policy, __g_first, __g_last, __g_pred);
90       },
91       std::move(__first),
92       std::move(__last),
93       std::move(__pred));
94 }
95 
96 _LIBCPP_END_NAMESPACE_STD
97 
98 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
99 
100 #endif // _LIBCPP___ALGORITHM_PSTL_ANY_ALL_NONE_OF_H
101