This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ensures that *__x, *__y and *__z are ordered according to the comparator __c, | |
// under the assumption that *__y and *__z are already ordered. | |
template <class _Compare, class _RandomAccessIterator> | |
inline void __partially_sorted_swap(_RandomAccessIterator __x, _RandomAccessIterator __y, | |
_RandomAccessIterator __z, _Compare __c) { | |
using value_type = typename iterator_traits<_RandomAccessIterator>::value_type; | |
bool __r = __c(*__z, *__x); | |
value_type __tmp = __r ? *__z : *__x; | |
*__z = __r ? *__x : *__z; | |
__r = __c(__tmp, *__y); | |
*__x = __r ? *__x : *__y; | |
} | |
template <class _Compare, class _RandomAccessIterator> | |
inline void __sort3(_RandomAccessIterator __x1, _RandomAccessIterator __x2, | |
_RandomAccessIterator __x3, _Compare __c) { | |
_VSTD::__cond_swap<_Compare>(__x2, __x3, __c); | |
_VSTD::__partially_sorted_swap<_Compare>(__x1, __x2, __x3, __c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think something's missing in
__partially_sorted_swap
.__tmp
is read from once to compare it with__y
, but its value is never stored anywhere. So is it missing*__y = __r ? __y : __tmp;
at the end?