#include #include class SampleClass : public Shareable { public: SampleClass(int* ptr, int value) : m_ptr(ptr), m_value(value) { } ~SampleClass() { if (m_ptr) *m_ptr = m_value; } private: int* m_ptr; int m_value; }; TestResult test_shared_ptr_destroyed_on_scope_exit() { static int value = 0; { SharedPtr sample = TRY(make_shared(&value, 1)); } validate(value == 1); test_success; } TestResult test_shared_ptr_preserved_if_at_least_one_copy_exists() { static int value = 0; static SharedPtr ptr = {}; { SharedPtr sample = TRY(make_shared(&value, 1)); ptr = sample; } validate(value == 0); ptr = {}; validate(value == 1); test_success; } Result test_main() { test_prelude; run_test(test_shared_ptr_destroyed_on_scope_exit); run_test(test_shared_ptr_preserved_if_at_least_one_copy_exists); return {}; }