aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/libcxx/include/__algorithm/nth_element.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-03-20 11:40:34 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-05-14 11:43:05 +0000
commit349cc55c9796c4596a5b9904cd3281af295f878f (patch)
tree410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/libcxx/include/__algorithm/nth_element.h
parentcb2ae6163174b90e999326ecec3699ee093a5d43 (diff)
parentc0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff)
Diffstat (limited to 'contrib/llvm-project/libcxx/include/__algorithm/nth_element.h')
-rw-r--r--contrib/llvm-project/libcxx/include/__algorithm/nth_element.h18
1 files changed, 11 insertions, 7 deletions
diff --git a/contrib/llvm-project/libcxx/include/__algorithm/nth_element.h b/contrib/llvm-project/libcxx/include/__algorithm/nth_element.h
index 67a03cfc37b0..63feba1ea616 100644
--- a/contrib/llvm-project/libcxx/include/__algorithm/nth_element.h
+++ b/contrib/llvm-project/libcxx/include/__algorithm/nth_element.h
@@ -16,13 +16,14 @@
#include <__iterator/iterator_traits.h>
#include <__utility/swap.h>
+#if defined(_LIBCPP_DEBUG_RANDOMIZE_UNSPECIFIED_STABILITY)
+# include <__algorithm/shuffle.h>
+#endif
+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
-_LIBCPP_PUSH_MACROS
-#include <__undef_macros>
-
_LIBCPP_BEGIN_NAMESPACE_STD
template<class _Compare, class _RandomAccessIterator>
@@ -225,8 +226,13 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
void
nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
{
- typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
- _VSTD::__nth_element<_Comp_ref>(__first, __nth, __last, __comp);
+ _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __last);
+ typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
+ _VSTD::__nth_element<_Comp_ref>(__first, __nth, __last, __comp);
+ _LIBCPP_DEBUG_RANDOMIZE_RANGE(__first, __nth);
+ if (__nth != __last) {
+ _LIBCPP_DEBUG_RANDOMIZE_RANGE(++__nth, __last);
+ }
}
template <class _RandomAccessIterator>
@@ -239,6 +245,4 @@ nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomA
_LIBCPP_END_NAMESPACE_STD
-_LIBCPP_POP_MACROS
-
#endif // _LIBCPP___ALGORITHM_NTH_ELEMENT_H