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_MERGE_H 10 #define _LIBCPP___ALGORITHM_PSTL_MERGE_H 11 12 #include <__algorithm/pstl_backend.h> 13 #include <__config> 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> 19 #include <optional> 20 21 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 22 # pragma GCC system_header 23 #endif 24 25 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 26 27 _LIBCPP_BEGIN_NAMESPACE_STD 28 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>( 46 _Backend{}, 47 std::move(__first1), 48 std::move(__last1), 49 std::move(__first2), 50 std::move(__last2), 51 std::move(__result), 52 std::move(__comp)); 53 } 54 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, 69 _Comp __comp = {}) { 70 auto __res = std::__merge( 71 __policy, 72 std::move(__first1), 73 std::move(__last1), 74 std::move(__first2), 75 std::move(__last2), 76 std::move(__result), 77 std::move(__comp)); 78 if (!__res) 79 std::__throw_bad_alloc(); 80 return *std::move(__res); 81 } 82 83 _LIBCPP_END_NAMESPACE_STD 84 85 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 86 87 #endif // _LIBCPP___ALGORITHM_PSTL_MERGE_H 88