• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
27 
28 _LIBCPP_BEGIN_NAMESPACE_STD
29 
30 template <class _ExecutionPolicy,
31           class _RandomAccessIterator,
32           class _Comp                                         = less<>,
33           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
34           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
35 [[nodiscard]] _LIBCPP_HIDE_FROM_ABI optional<__empty> __stable_sort(
36     _ExecutionPolicy&&, _RandomAccessIterator&& __first, _RandomAccessIterator&& __last, _Comp&& __comp = {}) noexcept {
37   using _Backend = typename __select_backend<_RawPolicy>::type;
38   return std::__pstl_stable_sort<_RawPolicy>(_Backend{}, std::move(__first), std::move(__last), std::move(__comp));
39 }
40 
41 template <class _ExecutionPolicy,
42           class _RandomAccessIterator,
43           class _Comp                                         = less<>,
44           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
45           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
46 _LIBCPP_HIDE_FROM_ABI void stable_sort(
47     _ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp = {}) {
48   if (!std::__stable_sort(__policy, std::move(__first), std::move(__last), std::move(__comp)))
49     std::__throw_bad_alloc();
50 }
51 
52 _LIBCPP_END_NAMESPACE_STD
53 
54 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
55 
56 #endif // _LIBCPP___ALGORITHM_PSTL_STABLE_SORT_H
57