Should I assign or reset a unique_ptr?

From the docs of unique_ptr‘s operator=:

Transfers ownership of the object pointed to by r to *this as if by calling reset(r.release()) followed by an assignment from std::forward<E>(r.get_deleter()).

And all you need of that is the reset call, so it’s simpler to just call it directly

Leave a Comment