Re:Mistakes to avoid with C++ 11 smart pointers
by millstone on Saturday May 14, 2016 @11:17PM
(#11699233)
It should be changed to pass by value, and then use std::move to move it into the children array. The reason is that if the argument is a temporary, you are making an unnecessary copy of that temporary, when you could just transfer ownership.
This also gives callers the flexibility to std::move into your argument, transferring ownership.
A good rule of thumb is, if you are going to unconditionally take ownership of an object, accept it by value.
Hum? What assignment into the object? Where I'd typically see taking a `const std::shared_ptr<> &` to signal "retaining ownership" would be something like this:
Why should Foo:;AppendChild's signature be changed to a non-const ref?