[libcxx-commits] [PATCH] D128983: [libcxx][ranges] implement `std::ranges::set_difference`

Hui via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 7 17:09:37 PDT 2022


huixie90 added inline comments.


================
Comment at: libcxx/include/__algorithm/set_difference.h:68-76
+  auto __ret = std::__set_difference(
+      __first1,
+      __last1,
+      __first2,
+      __last2,
+      __result,
+      __less<typename iterator_traits<_InputIterator1>::value_type,
----------------
philnik wrote:
> var-const wrote:
> > philnik wrote:
> > > Why aren't you returning `std::__set_difference(...).second` here? IIUC explicitly doing the move is either redundant because of implicit move or detrimental because of copy elision.
> > I think implicit move doesn't apply when returning a member of an object, even if the object itself is a local variable.
> https://godbolt.org/z/q1rj39Tdf looks to me a lot like an implicit move.
Double checked with several compilers, it is always a move
https://godbolt.org/z/GPTnzhj38

not because it is implicit move, it is because the expression  `make_pair(x, y).second` yields an rvalue reference to the second member,
so no need for explicit move here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128983



More information about the libcxx-commits mailing list