#include <iostream>
#include <memory>
using namespace std;
struct B;
struct A
{
shared_ptr<B> b;
~A()
{
std::cout << __PRETTY_FUNCTION__ << '\n';
}
};
struct B
{
weak_ptr<A> a;
~B()
{
std::cout << __PRETTY_FUNCTION__ << '\n';
}
};
int main()
{
shared_ptr<A> x(new A);
x->b.reset(new B);
x->b->a = x;
x->b->a.lock();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKc3RydWN0IEI7CnN0cnVjdCBBCnsKICAgIAogICAgc2hhcmVkX3B0cjxCPiBiOwogICAgfkEoKQogICAgewogICAgICAgIHN0ZDo6Y291dCA8PCBfX1BSRVRUWV9GVU5DVElPTl9fIDw8ICdcbic7CiAgICB9Cn07CgpzdHJ1Y3QgQgp7CiAgICB3ZWFrX3B0cjxBPiAgIGE7CiAgICB+QigpCiAgICB7CiAgICAgICAgc3RkOjpjb3V0IDw8IF9fUFJFVFRZX0ZVTkNUSU9OX18gPDwgJ1xuJzsKICAgIH0KCn07CgppbnQgbWFpbigpCnsKICAgIHNoYXJlZF9wdHI8QT4geChuZXcgQSk7CiAgICB4LT5iLnJlc2V0KG5ldyBCKTsKICAgIHgtPmItPmEgPSB4OwogICAgeC0+Yi0+YS5sb2NrKCk7CiAgICByZXR1cm4gMDsKfQo=