]> git.sesse.net Git - casparcg/blobdiff - common/memory/safe_ptr.h
2.0.0: Fixed potential pure virtual function call.
[casparcg] / common / memory / safe_ptr.h
index e4269e69bd2166f96f984fb8287e930b77aafa7a..88c184af3f6f796c2678fa48851a6b7eb9e3282a 100644 (file)
@@ -35,8 +35,8 @@ public:
        \r
        safe_ptr() : impl_(std::make_shared<T>()){}     \r
        \r
-       safe_ptr(const safe_ptr<T>& other) : impl_(other.impl_){}  // noexcept\r
-       safe_ptr(safe_ptr<T>&& other) : impl_(std::move(other.impl_)){}\r
+       safe_ptr(const safe_ptr& other) : impl_(other.impl_){}  // noexcept\r
+       safe_ptr(safe_ptr&& other) : impl_(std::move(other.impl_)){}\r
 \r
        template<typename U>\r
        safe_ptr(const safe_ptr<U>& other, typename std::enable_if<std::is_convertible<U*, T*>::value, void*>::type = 0) : impl_(other.impl_){}  // noexcept\r
@@ -86,19 +86,26 @@ public:
        }\r
 \r
        template<typename U>\r
-       typename std::enable_if<std::is_convertible<U*, T*>::value, safe_ptr<T>&>::type\r
+       typename std::enable_if<std::is_convertible<typename std::add_pointer<U>::type, T*>::value, safe_ptr&>::type\r
        operator=(const safe_ptr<U>& other)\r
        {\r
-               safe_ptr<T> temp(other);\r
-               temp.swap(*this);\r
+               safe_ptr(other).swap(*this);\r
+               return *this;\r
+       }\r
+\r
+       template<typename U>\r
+       typename std::enable_if<std::is_convertible<typename std::add_pointer<U>::type, T*>::value, safe_ptr&>::type\r
+       operator=(safe_ptr<U>&& other)\r
+       {\r
+               safe_ptr(std::move(other)).swap(*this);\r
                return *this;\r
        }\r
 \r
        template <typename U>\r
-       typename std::enable_if<std::is_convertible<typename std::add_pointer<U>::type, T*>::value, safe_ptr<T>&>::type\r
+       typename std::enable_if<std::is_convertible<typename std::add_pointer<U>::type, T*>::value, safe_ptr&>::type\r
        operator=(U&& impl)\r
        {\r
-               safe_ptr<T> temp(std::forward<T>(impl));\r
+               safe_ptr temp(std::forward<T>(impl));\r
                temp.swap(*this);\r
                return *this;\r
        }\r
@@ -127,7 +134,7 @@ public:
        operator const std::shared_ptr<T>&() const { return impl_;}  // noexcept\r
 \r
        template<class U>\r
-       bool owner_before(const safe_ptr<T>& ptr){ return impl_.owner_before(ptr.impl_); }  // noexcept\r
+       bool owner_before(const safe_ptr& ptr){ return impl_.owner_before(ptr.impl_); }  // noexcept\r
 \r
        template<class U>\r
        bool owner_before(const std::shared_ptr<U>& ptr){ return impl_.owner_before(ptr); }  // noexcept\r