• 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_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 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
28 
29 _LIBCPP_BEGIN_NAMESPACE_STD
30 
31 template <class>
32 void __pstl_is_partitioned();
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>
__is_partitioned(_ExecutionPolicy && __policy,_ForwardIterator && __first,_ForwardIterator && __last,_Predicate && __pred)39 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<bool> __is_partitioned(
40     _ExecutionPolicy&& __policy, _ForwardIterator&& __first, _ForwardIterator&& __last, _Predicate&& __pred) {
41   return std::__pstl_frontend_dispatch(
42       _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_is_partitioned, _RawPolicy),
43       [&__policy](_ForwardIterator __g_first, _ForwardIterator __g_last, _Predicate __g_pred) {
44         __g_first = std::find_if_not(__policy, __g_first, __g_last, __g_pred);
45         if (__g_first == __g_last)
46           return true;
47         ++__g_first;
48         return std::none_of(__policy, __g_first, __g_last, __g_pred);
49       },
50       std::move(__first),
51       std::move(__last),
52       std::move(__pred));
53 }
54 
55 template <class _ExecutionPolicy,
56           class _ForwardIterator,
57           class _Predicate,
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
is_partitioned(_ExecutionPolicy && __policy,_ForwardIterator __first,_ForwardIterator __last,_Predicate __pred)61 is_partitioned(_ExecutionPolicy&& __policy, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) {
62   auto __res = std::__is_partitioned(__policy, std::move(__first), std::move(__last), std::move(__pred));
63   if (!__res)
64     std::__throw_bad_alloc();
65   return *std::move(__res);
66 }
67 
68 _LIBCPP_END_NAMESPACE_STD
69 
70 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
71 
72 #endif // _LIBCPP___ALGORITHM_PSTL_IS_PARITTIONED
73