#include <memory>
#include <iostream>
class SomeClass {
public:
SomeClass() {
std::cout << "SomeClass()" << std::endl;
}
~SomeClass() {
std::cout << "~SomeClass()" << std::endl;
}
void* operator new(std::size_t size) {
std::cout << "Custom new" << std::endl;
return ::operator new(size);
}
void operator delete(void* ptr, std::size_t size) {
std::cout << "Custom delete" << std::endl;
::operator delete(ptr);
}
};
int main() {
std::shared_ptr<SomeClass> ptr1(new SomeClass);
std::cout << std::endl << "Another one..." << std::endl << std::endl;
std::shared_ptr<SomeClass> ptr2(std::make_shared<SomeClass>());
std::cout << std::endl << "Done!" << std::endl << std::endl;
}
I2luY2x1ZGUgPG1lbW9yeT4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKCmNsYXNzIFNvbWVDbGFzcyB7CnB1YmxpYzoKICAgIFNvbWVDbGFzcygpIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIlNvbWVDbGFzcygpIiA8PCBzdGQ6OmVuZGw7CiAgICB9CiAgICAKICAgIH5Tb21lQ2xhc3MoKSB7CiAgICAgICAgc3RkOjpjb3V0IDw8ICJ+U29tZUNsYXNzKCkiIDw8IHN0ZDo6ZW5kbDsKICAgIH0KCiAgICB2b2lkKiBvcGVyYXRvciBuZXcoc3RkOjpzaXplX3Qgc2l6ZSkgewogICAgICAgIHN0ZDo6Y291dCA8PCAiQ3VzdG9tIG5ldyIgPDwgc3RkOjplbmRsOwogICAgICAgIHJldHVybiA6Om9wZXJhdG9yIG5ldyhzaXplKTsKICAgIH0KICAgIAogICAgdm9pZCBvcGVyYXRvciBkZWxldGUodm9pZCogcHRyLCBzdGQ6OnNpemVfdCBzaXplKSB7CiAgICAgICAgc3RkOjpjb3V0IDw8ICJDdXN0b20gZGVsZXRlIiA8PCBzdGQ6OmVuZGw7CiAgICAgICAgOjpvcGVyYXRvciBkZWxldGUocHRyKTsKICAgIH0KfTsKCgoKaW50IG1haW4oKSB7CiAgICBzdGQ6OnNoYXJlZF9wdHI8U29tZUNsYXNzPiBwdHIxKG5ld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