#ifndef mock_types_1103988513531 #define mock_types_1103988513531 template struct RawPtrTraits { using StorageType = T*; template static T* exchange(StorageType& ptr, U&& newValue) { StorageType oldValue = static_cast(ptr); ptr = static_cast(newValue); return oldValue; } static void swap(StorageType& a, StorageType& b) { StorageType temp = static_cast(a); a = static_cast(b); b = static_cast(temp); } static T* unwrap(const StorageType& ptr) { return ptr; } }; template struct DefaultRefDerefTraits { static T* refIfNotNull(T* ptr) { if (ptr) ptr->ref(); return ptr; } static T& ref(T& ref) { ref.ref(); return ref; } static void derefIfNotNull(T* ptr) { if (ptr) ptr->deref(); } }; template , typename RefDerefTraits = DefaultRefDerefTraits> struct Ref { typename PtrTraits::StorageType t; Ref() : t{} {}; Ref(T &t) : t(&RefDerefTraits::ref(t)) { } Ref(const Ref& o) : t(RefDerefTraits::refIfNotNull(PtrTraits::unwrap(o.t))) { } Ref(Ref&& o) : t(o.leakRef()) { } ~Ref() { RefDerefTraits::derefIfNotNull(PtrTraits::exchange(t, nullptr)); } Ref& operator=(T &t) { Ref o(t); swap(o); return *this; } Ref& operator=(Ref &&o) { Ref m(o); swap(m); return *this; } void swap(Ref& o) { typename PtrTraits::StorageType tmp = t; t = o.t; o.t = tmp; } T &get() const { return *PtrTraits::unwrap(t); } T *ptr() const { return PtrTraits::unwrap(t); } T *operator->() const { return PtrTraits::unwrap(t); } operator T &() const { return *PtrTraits::unwrap(t); } T* leakRef() { return PtrTraits::exchange(t, nullptr); } }; template struct RefPtr { T *t; RefPtr() : t(new T) {} RefPtr(T *t) : t(t) { if (t) t->ref(); } RefPtr(Ref&& o) : t(o.leakRef()) { } ~RefPtr() { if (t) t->deref(); } Ref releaseNonNull() { Ref tmp(*t); if (t) t->deref(); t = nullptr; return tmp; } void swap(RefPtr& o) { T* tmp = t; t = o.t; o.t = tmp; } T *get() const { return t; } T *operator->() const { return t; } T &operator*() { return *t; } RefPtr &operator=(T *t) { RefPtr o(t); swap(o); return *this; } operator bool() const { return t; } }; template bool operator==(const RefPtr &, const RefPtr &) { return false; } template bool operator==(const RefPtr &, T *) { return false; } template bool operator==(const RefPtr &, T &) { return false; } template bool operator!=(const RefPtr &, const RefPtr &) { return false; } template bool operator!=(const RefPtr &, T *) { return false; } template bool operator!=(const RefPtr &, T &) { return false; } struct RefCountable { static Ref create(); void ref() {} void deref() {} void method(); void constMethod() const; int trivial() { return 123; } RefCountable* next(); }; template T *downcast(T *t) { return t; } template struct CheckedRef { private: T *t; public: CheckedRef() : t{} {}; CheckedRef(T &t) : t(&t) { t.incrementCheckedPtrCount(); } CheckedRef(const CheckedRef &o) : t(o.t) { if (t) t->incrementCheckedPtrCount(); } ~CheckedRef() { if (t) t->decrementCheckedPtrCount(); } T &get() const { return *t; } T *ptr() const { return t; } T *operator->() const { return t; } operator const T &() const { return *t; } operator T &() { return *t; } }; template struct CheckedPtr { private: T *t; public: CheckedPtr() : t(nullptr) {} CheckedPtr(T *t) : t(t) { if (t) t->incrementCheckedPtrCount(); } CheckedPtr(Ref &&o) : t(o.leakRef()) { } ~CheckedPtr() { if (t) t->decrementCheckedPtrCount(); } T *get() const { return t; } T *operator->() const { return t; } T &operator*() { return *t; } CheckedPtr &operator=(T *) { return *this; } operator bool() const { return t; } }; class CheckedObj { public: void incrementCheckedPtrCount(); void decrementCheckedPtrCount(); void method(); int trivial() { return 123; } }; class RefCountableAndCheckable { public: void incrementCheckedPtrCount() const; void decrementCheckedPtrCount() const; void ref() const; void deref() const; void method(); int trivial() { return 0; } }; template class UniqueRef { private: T *t; public: UniqueRef(T &t) : t(&t) { } ~UniqueRef() { if (t) delete t; } template UniqueRef(UniqueRef&& u) : t(u.t) { u.t = nullptr; } T &get() const { return *t; } T *operator->() const { return t; } UniqueRef &operator=(T &) { return *this; } }; namespace std { template class unique_ptr { private: T *t; public: unique_ptr() : t(nullptr) { } unique_ptr(T *t) : t(t) { } ~unique_ptr() { if (t) delete t; } template unique_ptr(unique_ptr&& u) : t(u.t) { u.t = nullptr; } T *get() const { return t; } T *operator->() const { return t; } T &operator*() { return *t; } unique_ptr &operator=(T *) { return *this; } }; }; #endif