class A {
public:
A() {
cout << "A" << endl;
}
~A() {
cout << "~A1" << endl;
sleep(5);
cout << "~A2" << endl;
}
};
int main()
{
std::unique_ptr<A> m_A = make_unique<A>();
cout << "~A1" << endl;
m_A.reset(nullptr);
cout << "~A2" << endl;
return 0;
}
/** @brief Replace the stored pointer.
*
* @param __p The new pointer to store.
*
* The deleter will be invoked if a pointer is already owned.
*/
void
reset(pointer __p = pointer()) noexcept
{
static_assert(__is_invocable<deleter_type&, pointer>::value,
"unique_ptr's deleter must be invocable with a pointer");
using std::swap;
swap(_M_t._M_ptr(), __p);
if (__p != pointer())
get_deleter()(std::move(__p));
}