Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:37

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___PSTL_CPU_ALGOS_MERGE_H
0010 #define _LIBCPP___CXX03___PSTL_CPU_ALGOS_MERGE_H
0011 
0012 #include <__cxx03/__algorithm/merge.h>
0013 #include <__cxx03/__assert>
0014 #include <__cxx03/__config>
0015 #include <__cxx03/__iterator/concepts.h>
0016 #include <__cxx03/__pstl/backend_fwd.h>
0017 #include <__cxx03/__pstl/cpu_algos/cpu_traits.h>
0018 #include <__cxx03/__type_traits/is_execution_policy.h>
0019 #include <__cxx03/__utility/move.h>
0020 #include <__cxx03/optional>
0021 
0022 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0023 #  pragma GCC system_header
0024 #endif
0025 
0026 _LIBCPP_PUSH_MACROS
0027 #include <__cxx03/__undef_macros>
0028 
0029 _LIBCPP_BEGIN_NAMESPACE_STD
0030 namespace __pstl {
0031 
0032 template <class _Backend, class _RawExecutionPolicy>
0033 struct __cpu_parallel_merge {
0034   template <class _Policy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardOutIterator, class _Comp>
0035   _LIBCPP_HIDE_FROM_ABI optional<_ForwardOutIterator> operator()(
0036       _Policy&& __policy,
0037       _ForwardIterator1 __first1,
0038       _ForwardIterator1 __last1,
0039       _ForwardIterator2 __first2,
0040       _ForwardIterator2 __last2,
0041       _ForwardOutIterator __result,
0042       _Comp __comp) const noexcept {
0043     if constexpr (__is_parallel_execution_policy_v<_RawExecutionPolicy> &&
0044                   __has_random_access_iterator_category_or_concept<_ForwardIterator1>::value &&
0045                   __has_random_access_iterator_category_or_concept<_ForwardIterator2>::value &&
0046                   __has_random_access_iterator_category_or_concept<_ForwardOutIterator>::value) {
0047       auto __res = __cpu_traits<_Backend>::__merge(
0048           __first1,
0049           __last1,
0050           __first2,
0051           __last2,
0052           __result,
0053           __comp,
0054           [&__policy](_ForwardIterator1 __g_first1,
0055                       _ForwardIterator1 __g_last1,
0056                       _ForwardIterator2 __g_first2,
0057                       _ForwardIterator2 __g_last2,
0058                       _ForwardOutIterator __g_result,
0059                       _Comp __g_comp) {
0060             using _MergeUnseq             = __pstl::__merge<_Backend, __remove_parallel_policy_t<_RawExecutionPolicy>>;
0061             [[maybe_unused]] auto __g_res = _MergeUnseq()(
0062                 std::__remove_parallel_policy(__policy),
0063                 std::move(__g_first1),
0064                 std::move(__g_last1),
0065                 std::move(__g_first2),
0066                 std::move(__g_last2),
0067                 std::move(__g_result),
0068                 std::move(__g_comp));
0069             _LIBCPP_ASSERT_INTERNAL(__g_res, "unsed/sed should never try to allocate!");
0070           });
0071       if (!__res)
0072         return nullopt;
0073       return __result + (__last1 - __first1) + (__last2 - __first2);
0074     } else {
0075       return std::merge(__first1, __last1, __first2, __last2, __result, __comp);
0076     }
0077   }
0078 };
0079 
0080 } // namespace __pstl
0081 _LIBCPP_END_NAMESPACE_STD
0082 
0083 _LIBCPP_POP_MACROS
0084 
0085 #endif // _LIBCPP___CXX03___PSTL_CPU_ALGOS_MERGE_H