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_POP_HEAP_H 10 #define _LIBCPP___ALGORITHM_POP_HEAP_H 11 12 #include <__algorithm/comp.h> 13 #include <__algorithm/comp_ref_type.h> 14 #include <__algorithm/sift_down.h> 15 #include <__config> 16 #include <__iterator/iterator_traits.h> 17 #include <__utility/swap.h> 18 19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 20 # pragma GCC system_header 21 # pragma clang include_instead(<algorithm>) 22 #endif 23 24 _LIBCPP_BEGIN_NAMESPACE_STD 25 26 template <class _Compare, class _RandomAccessIterator> 27 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 28 void 29 __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, 30 typename iterator_traits<_RandomAccessIterator>::difference_type __len) 31 { 32 if (__len > 1) 33 { 34 swap(*__first, *--__last); 35 _VSTD::__sift_down<_Compare>(__first, __comp, __len - 1, __first); 36 } 37 } 38 39 template <class _RandomAccessIterator, class _Compare> 40 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 41 void 42 pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) 43 { 44 typedef typename __comp_ref_type<_Compare>::type _Comp_ref; 45 _VSTD::__pop_heap<_Comp_ref>(__first, __last, __comp, __last - __first); 46 } 47 48 template <class _RandomAccessIterator> 49 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 50 void 51 pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) 52 { 53 _VSTD::pop_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); 54 } 55 56 _LIBCPP_END_NAMESPACE_STD 57 58 #endif // _LIBCPP___ALGORITHM_POP_HEAP_H 59