|
13 | 13 | #include <__algorithm/comp_ref_type.h>
|
14 | 14 | #include <__algorithm/push_heap.h>
|
15 | 15 | #include <__algorithm/sift_down.h>
|
| 16 | +#include <__assert> |
16 | 17 | #include <__config>
|
17 | 18 | #include <__iterator/iterator_traits.h>
|
18 | 19 | #include <__utility/move.h>
|
|
24 | 25 | _LIBCPP_BEGIN_NAMESPACE_STD
|
25 | 26 |
|
26 | 27 | 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 |
| - using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; |
| 28 | +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 29 | +void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare& __comp, |
| 30 | + typename iterator_traits<_RandomAccessIterator>::difference_type __len) { |
| 31 | + _LIBCPP_ASSERT(__len > 0, "The heap given to pop_heap must be non-empty"); |
33 | 32 |
|
34 |
| - if (__len > 1) |
35 |
| - { |
36 |
| - value_type __top = std::move(*__first); // create a hole at __first |
37 |
| - _RandomAccessIterator __hole = std::__floyd_sift_down<_Compare>(__first, __comp, __len); |
38 |
| - --__last; |
39 |
| - if (__hole == __last) { |
40 |
| - *__hole = std::move(__top); |
41 |
| - } else { |
42 |
| - *__hole = std::move(*__last); |
43 |
| - ++__hole; |
44 |
| - *__last = std::move(__top); |
45 |
| - std::__sift_up<_Compare>(__first, __hole, __comp, __hole - __first); |
46 |
| - } |
| 33 | + using _CompRef = typename __comp_ref_type<_Compare>::type; |
| 34 | + _CompRef __comp_ref = __comp; |
| 35 | + |
| 36 | + using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; |
| 37 | + if (__len > 1) { |
| 38 | + value_type __top = std::move(*__first); // create a hole at __first |
| 39 | + _RandomAccessIterator __hole = std::__floyd_sift_down<_CompRef>(__first, __comp_ref, __len); |
| 40 | + --__last; |
| 41 | + |
| 42 | + if (__hole == __last) { |
| 43 | + *__hole = std::move(__top); |
| 44 | + } else { |
| 45 | + *__hole = std::move(*__last); |
| 46 | + ++__hole; |
| 47 | + *__last = std::move(__top); |
| 48 | + std::__sift_up<_CompRef>(__first, __hole, __comp_ref, __hole - __first); |
47 | 49 | }
|
| 50 | + } |
48 | 51 | }
|
49 | 52 |
|
50 | 53 | template <class _RandomAccessIterator, class _Compare>
|
51 |
| -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
52 |
| -void |
53 |
| -pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) |
54 |
| -{ |
55 |
| - typedef typename __comp_ref_type<_Compare>::type _Comp_ref; |
56 |
| - _VSTD::__pop_heap<_Comp_ref>(__first, __last, __comp, __last - __first); |
| 54 | +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 55 | +void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { |
| 56 | + typename iterator_traits<_RandomAccessIterator>::difference_type __len = __last - __first; |
| 57 | + std::__pop_heap(std::move(__first), std::move(__last), __comp, __len); |
57 | 58 | }
|
58 | 59 |
|
59 | 60 | template <class _RandomAccessIterator>
|
60 |
| -inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
61 |
| -void |
62 |
| -pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) |
63 |
| -{ |
64 |
| - _VSTD::pop_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); |
| 61 | +inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 62 | +void pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) { |
| 63 | + std::pop_heap(std::move(__first), std::move(__last), |
| 64 | + __less<typename iterator_traits<_RandomAccessIterator>::value_type>()); |
65 | 65 | }
|
66 | 66 |
|
67 | 67 | _LIBCPP_END_NAMESPACE_STD
|
|
0 commit comments