File indexing completed on 2026-05-03 08:13:59
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___PSTL_CPU_ALGOS_STABLE_SORT_H
0010 #define _LIBCPP___PSTL_CPU_ALGOS_STABLE_SORT_H
0011
0012 #include <__algorithm/stable_sort.h>
0013 #include <__config>
0014 #include <__pstl/backend_fwd.h>
0015 #include <__pstl/cpu_algos/cpu_traits.h>
0016 #include <__type_traits/is_execution_policy.h>
0017 #include <__utility/empty.h>
0018 #include <optional>
0019
0020 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0021 # pragma GCC system_header
0022 #endif
0023
0024 #if _LIBCPP_STD_VER >= 17
0025
0026 _LIBCPP_BEGIN_NAMESPACE_STD
0027 namespace __pstl {
0028
0029 template <class _Backend, class _RawExecutionPolicy>
0030 struct __cpu_parallel_stable_sort {
0031 template <class _Policy, class _RandomAccessIterator, class _Comp>
0032 _LIBCPP_HIDE_FROM_ABI optional<__empty>
0033 operator()(_Policy&&, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) const noexcept {
0034 if constexpr (__is_parallel_execution_policy_v<_RawExecutionPolicy>) {
0035 return __cpu_traits<_Backend>::__stable_sort(
0036 __first, __last, __comp, [](_RandomAccessIterator __g_first, _RandomAccessIterator __g_last, _Comp __g_comp) {
0037 std::stable_sort(__g_first, __g_last, __g_comp);
0038 });
0039 } else {
0040 std::stable_sort(__first, __last, __comp);
0041 return __empty{};
0042 }
0043 }
0044 };
0045
0046 }
0047 _LIBCPP_END_NAMESPACE_STD
0048
0049 #endif
0050
0051 #endif