1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___ALGORITHM_PSTL_ANY_ALL_NONE_OF_H
10 #define _LIBCPP___ALGORITHM_PSTL_ANY_ALL_NONE_OF_H
12 #include <__algorithm/pstl_find.h>
13 #include <__algorithm/pstl_frontend_dispatch.h>
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>
22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23 # pragma GCC system_header
26 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
28 _LIBCPP_BEGIN_NAMESPACE_STD
31 void __pstl_any_of(); // declaration needed for the frontend dispatch below
33 template <class _ExecutionPolicy
,
34 class _ForwardIterator
,
36 class _RawPolicy
= __remove_cvref_t
<_ExecutionPolicy
>,
37 enable_if_t
<is_execution_policy_v
<_RawPolicy
>, int> = 0>
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
);
46 return *__res
!= __g_last
;
53 template <class _ExecutionPolicy
,
54 class _ForwardIterator
,
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
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
));
63 std::__throw_bad_alloc();
64 return *std::move(__res
);
68 void __pstl_all_of(); // declaration needed for the frontend dispatch below
70 template <class _ExecutionPolicy
,
71 class _ForwardIterator
,
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>
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
);
92 template <class _ExecutionPolicy
,
93 class _ForwardIterator
,
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
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
));
102 std::__throw_bad_alloc();
103 return *std::move(__res
);
107 void __pstl_none_of(); // declaration needed for the frontend dispatch below
109 template <class _ExecutionPolicy
,
110 class _ForwardIterator
,
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>
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
);
129 template <class _ExecutionPolicy
,
130 class _ForwardIterator
,
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
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
));
139 std::__throw_bad_alloc();
140 return *std::move(__res
);
143 _LIBCPP_END_NAMESPACE_STD
145 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
147 #endif // _LIBCPP___ALGORITHM_PSTL_ANY_ALL_NONE_OF_H