[libcxx-commits] [PATCH] D141614: [libc++] nth_element change to partial sort when range is really small

Zhikai Zeng via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Feb 25 03:47:00 PST 2023


Backl1ght added inline comments.


================
Comment at: libcxx/include/__algorithm/nth_element.h:42
+  for (; __first != __middle; ++__first) {
+    _BidirectionalIterator __i = std::__min_element(__first, __last, __comp);
+    if (__i != __first)
----------------
philnik wrote:
> Why not `min_element`? Using the public API makes it always easier to refactor internal stuff, since that part is stable.
I use `__min_element` since `selection_sort` in `sort.h` uses `__min_element`.

I agree with that using the public API will be better. So I tried using `min_element` but got fail in a unittest defined in `ranges_robust_against_proxy_iterators.pass.cpp`.

I find out that `selection_sort` in `sort.h` used `min_element` before and changed to `__min_element` in D129823 to make range algorithms support proxy iterators


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141614/new/

https://reviews.llvm.org/D141614



More information about the libcxx-commits mailing list