#include <iostream>
#include <memory>
class Object
{
public :
//...potentially lots of data...
} ;
class ObjectHandle
{
public :
ObjectHandle( ) { std:: cout << "Constructed" << std:: endl ; }
~ObjectHandle( ) { std:: cout << "Destructed" << std:: endl ; }
private :
Object * ptrToPotentiallyLotsOfData = nullptr;
} ;
int main( )
{
std:: cout << "ObjectHandle size: " << sizeof ( ObjectHandle) << std:: endl ;
std:: cout << ( std:: is_pod < ObjectHandle> :: value ? "Is plain-ol`-data" : "Is not plain-old-data" ) << std:: endl ;
std:: cout << "\n Scope began" << std:: endl ;
{
std:: shared_ptr < ObjectHandle> objectSPtr = std:: make_shared < ObjectHandle> ( ) ;
std:: weak_ptr < ObjectHandle> objectWPtr = objectSPtr;
std:: cout << "Resetting shared_ptr" << std:: endl ;
objectSPtr.reset ( ) ;
std:: cout << "Done resetting shared_ptr" << std:: endl ;
}
std:: cout << "Scope ended" << std:: endl ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgoKY2xhc3MgT2JqZWN0CnsKcHVibGljOgkKICAgLy8uLi5wb3RlbnRpYWxseSBsb3RzIG9mIGRhdGEuLi4KfTsKCmNsYXNzIE9iamVjdEhhbmRsZQp7CnB1YmxpYzoJCiAgIE9iamVjdEhhbmRsZSgpIHsgc3RkOjpjb3V0IDw8ICJDb25zdHJ1Y3RlZCIgPDwgc3RkOjplbmRsOyB9CiAgIH5PYmplY3RIYW5kbGUoKSB7IHN0ZDo6Y291dCA8PCAiRGVzdHJ1Y3RlZCIgPDwgc3RkOjplbmRsOyB9CiAgIApwcml2YXRlOgogICAgT2JqZWN0ICpwdHJUb1BvdGVudGlhbGx5TG90c09mRGF0YSA9IG51bGxwdHI7Cn07CgppbnQgbWFpbigpCnsKCXN0ZDo6Y291dCA8PCAiT2JqZWN0SGFuZGxlIHNpemU6ICIgPDwgc2l6ZW9mKE9iamVjdEhhbmRsZSkgPDwgc3RkOjplbmRsOwoJc3RkOjpjb3V0IDw8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