From 35f95fd067fd1c5ce6cf25383e6579f66cc48e64 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 8 Oct 2016 14:48:57 -0400 Subject: [PATCH] Make ref(owned) explicit. --- zcpointer.h | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/zcpointer.h b/zcpointer.h index 2edf05f..27bffa9 100644 --- a/zcpointer.h +++ b/zcpointer.h @@ -87,7 +87,7 @@ class owned : public std::unique_ptr> { template class ref { public: - ref(owned& o) : ptr_(o.GetRawPointer()), deleter_(o.get_deleter()) { + explicit ref(owned& o) : ptr_(o.GetRawPointer()), deleter_(o.get_deleter()) { deleter_.AddRef(this); } @@ -98,38 +98,19 @@ class ref { } ref& operator=(ref o) { - ptr_ = o.ptr_; - deleter_ = o.deleter_; - deleted_ = o.deleted_; - if (!deleted_) { - deleter_.AddRef(this); - } - return *this; + return ref(o); } ~ref() { + MarkDeleted(); deleter_.RemoveRef(this); } -#if 0 - operator T*() const { - CheckDeleted(); - return ptr_; - } -#endif - T* operator->() const { CheckDeleted(); return ptr_; } -#if 0 - T* get() { - CheckDeleted(); - return ptr_; - } -#endif - protected: friend class internal::OwnedPtrDeleter; -- 2.43.5