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_IS_PARITTIONED
10 #define _LIBCPP___ALGORITHM_PSTL_IS_PARITTIONED
11
12 #include <__algorithm/pstl_any_all_none_of.h>
13 #include <__algorithm/pstl_backend.h>
14 #include <__algorithm/pstl_find.h>
15 #include <__algorithm/pstl_frontend_dispatch.h>
16 #include <__config>
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 <optional>
22
23 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24 # pragma GCC system_header
25 #endif
26
27 _LIBCPP_PUSH_MACROS
28 #include <__undef_macros>
29
30 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
31
32 _LIBCPP_BEGIN_NAMESPACE_STD
33
34 template <class>
35 void __pstl_is_partitioned();
36
37 template <class _ExecutionPolicy,
38 class _ForwardIterator,
39 class _Predicate,
40 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
41 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
__is_partitioned(_ExecutionPolicy && __policy,_ForwardIterator && __first,_ForwardIterator && __last,_Predicate && __pred)42 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool> __is_partitioned(
43 _ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Predicate&& __pred) {
44 return std::__pstl_frontend_dispatch(
45 _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_is_partitioned, _RawPolicy),
46 [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
47 __g_first = std::find_if_not(__policy, __g_first, __g_last, __g_pred);
48 if (__g_first == __g_last)
49 return true;
50 ++__g_first;
51 return std::none_of(__policy, __g_first, __g_last, __g_pred);
52 },
53 std::move(__first),
54 std::move(__last),
55 std::move(__pred));
56 }
57
58 template <class _ExecutionPolicy,
59 class _ForwardIterator,
60 class _Predicate,
61 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>,
62 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
63 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI bool
is_partitioned(_ExecutionPolicy && __policy,_ForwardIterator __first,_ForwardIterator __last,_Predicate __pred)64 is_partitioned(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
65 auto __res = std::__is_partitioned(__policy, std::move(__first), std::move(__last), std::move(__pred));
66 if (!__res)
67 std::__throw_bad_alloc();
68 return *std::move(__res);
69 }
70
71 _LIBCPP_END_NAMESPACE_STD
72
73 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
74
75 _LIBCPP_POP_MACROS
76
77 #endif // _LIBCPP___ALGORITHM_PSTL_IS_PARITTIONED
78