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