Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:12

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___ALGORITHM_SORT_HEAP_H
0010 #define _LIBCPP___ALGORITHM_SORT_HEAP_H
0011 
0012 #include <__algorithm/comp.h>
0013 #include <__algorithm/comp_ref_type.h>
0014 #include <__algorithm/iterator_operations.h>
0015 #include <__algorithm/pop_heap.h>
0016 #include <__config>
0017 #include <__debug_utils/strict_weak_ordering_check.h>
0018 #include <__iterator/iterator_traits.h>
0019 #include <__type_traits/is_assignable.h>
0020 #include <__type_traits/is_constructible.h>
0021 #include <__utility/move.h>
0022 
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 #  pragma GCC system_header
0025 #endif
0026 
0027 _LIBCPP_PUSH_MACROS
0028 #include <__undef_macros>
0029 
0030 _LIBCPP_BEGIN_NAMESPACE_STD
0031 
0032 template <class _AlgPolicy, class _Compare, class _RandomAccessIterator>
0033 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
0034 __sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
0035   _RandomAccessIterator __saved_last   = __last;
0036   __comp_ref_type<_Compare> __comp_ref = __comp;
0037 
0038   using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
0039   for (difference_type __n = __last - __first; __n > 1; --__last, (void)--__n)
0040     std::__pop_heap<_AlgPolicy>(__first, __last, __comp_ref, __n);
0041   std::__check_strict_weak_ordering_sorted(__first, __saved_last, __comp_ref);
0042 }
0043 
0044 template <class _RandomAccessIterator, class _Compare>
0045 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0046 sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) {
0047   static_assert(std::is_copy_constructible<_RandomAccessIterator>::value, "Iterators must be copy constructible.");
0048   static_assert(std::is_copy_assignable<_RandomAccessIterator>::value, "Iterators must be copy assignable.");
0049 
0050   std::__sort_heap<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __comp);
0051 }
0052 
0053 template <class _RandomAccessIterator>
0054 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
0055 sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) {
0056   std::sort_heap(std::move(__first), std::move(__last), __less<>());
0057 }
0058 
0059 _LIBCPP_END_NAMESPACE_STD
0060 
0061 _LIBCPP_POP_MACROS
0062 
0063 #endif // _LIBCPP___ALGORITHM_SORT_HEAP_H