File indexing completed on 2026-05-03 08:13:08
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___ALGORITHM_MAKE_HEAP_H
0010 #define _LIBCPP___ALGORITHM_MAKE_HEAP_H
0011
0012 #include <__algorithm/comp.h>
0013 #include <__algorithm/comp_ref_type.h>
0014 #include <__algorithm/iterator_operations.h>
0015 #include <__algorithm/sift_down.h>
0016 #include <__config>
0017 #include <__iterator/iterator_traits.h>
0018 #include <__utility/move.h>
0019
0020 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0021 # pragma GCC system_header
0022 #endif
0023
0024 _LIBCPP_PUSH_MACROS
0025 #include <__undef_macros>
0026
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028
0029 template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
0030 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
0031 __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
0032 __comp_ref_type<_Compare> __comp_ref = __comp;
0033
0034 using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
0035 difference_type __n = __last - __first;
0036 if (__n > 1) {
0037
0038 for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start) {
0039 std::__sift_down<_AlgPolicy>(__first, __comp_ref, __n, __first + __start);
0040 }
0041 }
0042 }
0043
0044 template <class _RandomAccessIterator, class _Compare>
0045 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0046 make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
0047 std::__make_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
0048 }
0049
0050 template <class _RandomAccessIterator>
0051 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0052 make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
0053 std::make_heap(std::move(__first), std::move(__last), __less<>());
0054 }
0055
0056 _LIBCPP_END_NAMESPACE_STD
0057
0058 _LIBCPP_POP_MACROS
0059
0060 #endif