For std::unique_ptrs p1 and p2, what are differences between std::move() and std::unique_ptr::reset()?
p1 = std::move(p2);
p1.reset(p2.release());
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The answer should be obvious from the standard’s specification of move assignment in [unique.ptr.single.assign]/2:
Clearly move assignment is not the same as
reset(u.release())because it does something additional.The additional effect is important, without it you can get undefined behaviour with custom deleters: