[libcxx-commits] [PATCH] D142864: [libc++] `<algorithm>`: `ranges::minmax` should dereference iterators only once
Igor Zhukov via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 7 04:52:35 PST 2023
fsb4000 marked an inline comment as done.
fsb4000 added inline comments.
================
Comment at: libcxx/include/__algorithm/ranges_minmax.h:140
+ // This initialization is correct, similar to the N4928 [dcl.init.aggr]/6 example
+ minmax_result<_ValueT> __result = {static_cast<_ValueT>(*__found_min), __result.min};
+ return __result;
----------------
philnik wrote:
> What are these `static_cast`s for?
MS STL uses the `static_cast`s. I used for consistency with MS STL. I asked them why the static_cast are needed and I added more `static_cast`s here. After their answer and if the `static_cast`s are optionally needed I could remove them.
================
Comment at: libcxx/include/__algorithm/ranges_minmax.h:149
+
+ while (++__first != __last) { // process one or two elements
+ _It __prev = __first;
----------------
philnik wrote:
> Why are you effectively re-implementing `minmax_element` here?
To implement `special-case the one element case` without adding an addional if.
Ok, I try another approach.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142864/new/
https://reviews.llvm.org/D142864
More information about the libcxx-commits
mailing list