I like the use of explicit std::move to specify intent at the callsite. I'd love the same for std::copy, as in: a = std::copy(b). Right now my containers/etc have a copy_from method with implicit copies disabled, but I'm sure I could engineer something trivial for this.
This is a bit of an aside, but while your first case is certainly better just as RVO, the second case is perfectly fine and encouraged in certain cases. Example: Functions that intend to “clone and own” arguments should take by value and let the caller decide move or copy.
-
-
Only if the function doing that acts like a "sink": f(A a) if condition return g(move(a)) else mutateA(a) ... saveA(move(a)) No dangling moved object used in any branch
-
Yes. Definitely what I meant by clone and own.
Keskustelun loppu
Uusi keskustelu -
Lataaminen näyttää kestävän hetken.
Twitter saattaa olla ruuhkautunut tai ongelma on muuten hetkellinen. Yritä uudelleen tai käy Twitterin tilasivulla saadaksesi lisätietoja.