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_STABLE_SORT_H 10 #define _LIBCPP___ALGORITHM_PSTL_STABLE_SORT_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/empty.h> 19 #include <__utility/move.h> 20 #include <optional> 21 22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 23 # pragma GCC system_header 24 #endif 25 26 _LIBCPP_PUSH_MACROS 27 #include <__undef_macros> 28 29 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 30 31 _LIBCPP_BEGIN_NAMESPACE_STD 32 33 template <class _ExecutionPolicy, 34 class _RandomAccessIterator, 35 class _Comp = less<>, 36 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, 37 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> 38 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty> __stable_sort( 39 _ExecutionPolicy&&, _RandomAccessIterator&& __first, _RandomAccessIterator&& __last, _Comp&& __comp = {}) noexcept { 40 using _Backend = typename __select_backend<_RawPolicy>::type; 41 return std::__pstl_stable_sort<_RawPolicy>(_Backend{}, std::move(__first), std::move(__last), std::move(__comp)); 42 } 43 44 template <class _ExecutionPolicy, 45 class _RandomAccessIterator, 46 class _Comp = less<>, 47 class _RawPolicy = __remove_cvref_t<_ExecutionPolicy>, 48 enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0> 49 _LIBCPP_HIDE_FROM_ABI void stable_sort( 50 _ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp = {}) { 51 if (!std::__stable_sort(__policy, std::move(__first), std::move(__last), std::move(__comp))) 52 std::__throw_bad_alloc(); 53 } 54 55 _LIBCPP_END_NAMESPACE_STD 56 57 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17 58 59 _LIBCPP_POP_MACROS 60 61 #endif // _LIBCPP___ALGORITHM_PSTL_STABLE_SORT_H 62