Hacker News new | past | comments | ask | show | jobs | submit login

Its idiomatic sure but specifically with shared pointer a lot of time people are using shared pointers because they don't want to think about ownership, this turns out not to be the case here but think about it, the function is taking shared_ptr by value which increases the ref count when looked at from the signature.

In the calling code you then dereference that shared_ptr because it should still be valid but it isn't because it is now a moved from value.

I would in this specific case just replace shared_ptr with unique_ptr in the entire call stack up until here. If there isn't an implicit conversation here, put the conversation to shared in this function.

That makes it explicit ownership of the pointer is being moved into this function, it wasn't clear at all that that is happening with the shared_ptr.

EDIT:

You have to think of shared_ptr as global, if you moved from it ownership was changed but there is no way for everyone else holding a reference to thay shared pointer to know that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: