2

When passing an std::unique_ptr by value (or an rvalue reference) the user is explicitly forced to call std::move (or cast to rvalue) thus resulting in greater clarity. However when one is passed by lvalue reference the method being called can simply call std::move itself, also transferring ownership, but with shorter user code. So, the question is:

When an object takes ownership of an object via an std::unique_ptr, is the convention to pass it by value, rvalue reference or lvalue reference?

Santiago Varela
  • 2,089
  • 14
  • 22
JeremiahB
  • 855
  • 8
  • 15
  • 1
    You can pass by lvalue reference for something like a repeated trial-and-error scheme, where you ask, "will you take my pointer?", and then you can check the result by looking at what's left behind. – Kerrek SB Mar 22 '17 at 02:55

0 Answers0