by usefulcat · 6y ago · 0 comments
I mean, I guess it's a way to avoid this particular problem (https://godbolt.org/z/8g6HJg), but even without passing shared_ptr by const ref that code still has a far worse code smell, namely the way it mixes manual and automated memory management. After all, the whole point of creating a shared_ptr instance is to take (possibly shared) ownership of a thing.
foo(shared_ptr<T> const &x) {
saved_x = x;
}
and it'll update the refcount exactly once when doing the assignment.