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_MERGE_H
10 #define _LIBCPP___ALGORITHM_PSTL_MERGE_H
12 #include <__algorithm/pstl_backend.h>
14 #include <__functional/operations.h>
15 #include <__type_traits/enable_if.h>
16 #include <__type_traits/is_execution_policy.h>
17 #include <__type_traits/remove_cvref.h>
18 #include <__utility/move.h>
21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
22 # pragma GCC system_header
25 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
27 _LIBCPP_BEGIN_NAMESPACE_STD
29 template <class _ExecutionPolicy
,
30 class _ForwardIterator1
,
31 class _ForwardIterator2
,
32 class _ForwardOutIterator
,
33 class _Comp
= std::less
<>,
34 class _RawPolicy
= __remove_cvref_t
<_ExecutionPolicy
>,
35 enable_if_t
<is_execution_policy_v
<_RawPolicy
>, int> = 0>
36 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI optional
<_ForwardOutIterator
>
37 __merge(_ExecutionPolicy
&&,
38 _ForwardIterator1 __first1
,
39 _ForwardIterator1 __last1
,
40 _ForwardIterator2 __first2
,
41 _ForwardIterator2 __last2
,
42 _ForwardOutIterator __result
,
43 _Comp __comp
= {}) noexcept
{
44 using _Backend
= typename __select_backend
<_RawPolicy
>::type
;
45 return std::__pstl_merge
<_RawPolicy
>(
55 template <class _ExecutionPolicy
,
56 class _ForwardIterator1
,
57 class _ForwardIterator2
,
58 class _ForwardOutIterator
,
59 class _Comp
= std::less
<>,
60 class _RawPolicy
= __remove_cvref_t
<_ExecutionPolicy
>,
61 enable_if_t
<is_execution_policy_v
<_RawPolicy
>, int> = 0>
62 _LIBCPP_HIDE_FROM_ABI _ForwardOutIterator
63 merge(_ExecutionPolicy
&& __policy
,
64 _ForwardIterator1 __first1
,
65 _ForwardIterator1 __last1
,
66 _ForwardIterator2 __first2
,
67 _ForwardIterator2 __last2
,
68 _ForwardOutIterator __result
,
70 auto __res
= std::__merge(
79 std::__throw_bad_alloc();
80 return *std::move(__res
);
83 _LIBCPP_END_NAMESPACE_STD
85 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
87 #endif // _LIBCPP___ALGORITHM_PSTL_MERGE_H