#include <iostream>
#include <memory>
using namespace std;
class T;
std::weak_ptr<T> wptr;
class T
{
public:
T() { }
~T() {
std::cout << "in dtor" << std::endl;
std::cout << (wptr.expired() ? "expired" : "not expired") << std::endl;
}
};
int main() {
{
auto ptr = std::make_shared<T>();
wptr = ptr;
std::cout << (wptr.expired() ? "expired" : "not expired") << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgVDsKCnN0ZDo6d2Vha19wdHI8VD4gd3B0cjsKCmNsYXNzIFQKewpwdWJsaWM6CglUKCkgeyAgfQoJflQoKSB7CgkJc3RkOjpjb3V0IDw8ICJpbiBkdG9yIiA8PCBzdGQ6OmVuZGw7CgkJc3RkOjpjb3V0IDw8ICh3cHRyLmV4cGlyZWQoKSA/ICJleHBpcmVkIiA6ICJub3QgZXhwaXJlZCIpIDw8IHN0ZDo6ZW5kbDsKCX0KfTsKCmludCBtYWluKCkgewoJewoJCWF1dG8gcHRyID0gc3RkOjptYWtlX3NoYXJlZDxUPigpOwoJCXdwdHIgPSBwdHI7CgkJc3RkOjpjb3V0IDw8ICh3cHRyLmV4cGlyZWQoKSA/ICJleHBpcmVkIiA6ICJub3QgZXhwaXJlZCIpIDw8IHN0ZDo6ZW5kbDsKCX0KCXJldHVybiAwOwp9