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_SORT_H
10 #define _LIBCPP___ALGORITHM_PSTL_SORT_H
11 
12 #include <__algorithm/pstl_backend.h>
13 #include <__algorithm/pstl_frontend_dispatch.h>
14 #include <__algorithm/pstl_stable_sort.h>
15 #include <__config>
16 #include <__functional/operations.h>
17 #include <__type_traits/is_execution_policy.h>
18 #include <__type_traits/remove_cvref.h>
19 #include <__utility/forward.h>
20 #include <__utility/move.h>
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>
31 void __pstl_sort();
32 
33 template <class _ExecutionPolicy,
34           class _RandomAccessIterator,
35           class _Comp,
36           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
37           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
38 _LIBCPP_HIDE_FROM_ABI void
39 sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last, _Comp __comp) {
40   std::__pstl_frontend_dispatch(
41       _LIBCPP_PSTL_CUSTOMIZATION_POINT(__pstl_sort),
42       [&__policy](_RandomAccessIterator __g_first, _RandomAccessIterator __g_last, _Comp __g_comp) {
43         std::stable_sort(__policy, std::move(__g_first), std::move(__g_last), std::move(__g_comp));
44       },
45       std::move(__first),
46       std::move(__last),
47       std::move(__comp));
48 }
49 
50 template <class _ExecutionPolicy,
51           class _RandomAccessIterator,
52           class _RawPolicy                                    = __remove_cvref_t<_ExecutionPolicy>,
53           enable_if_t<is_execution_policy_v<_RawPolicy>, int> = 0>
54 _LIBCPP_HIDE_FROM_ABI void
55 sort(_ExecutionPolicy&& __policy, _RandomAccessIterator __first, _RandomAccessIterator __last) {
56   std::sort(std::forward<_ExecutionPolicy>(__policy), std::move(__first), std::move(__last), less{});
57 }
58 
59 _LIBCPP_END_NAMESPACE_STD
60 
61 #endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_PSTL) && _LIBCPP_STD_VER >= 17
62 
63 #endif // _LIBCPP___ALGORITHM_PSTL_SORT_H
64