X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Fmemory%2Fsafe_ptr.h;h=88c184af3f6f796c2678fa48851a6b7eb9e3282a;hb=11e9ee9363a33cee4f3433c83b1f5fd76b95b57e;hp=e4269e69bd2166f96f984fb8287e930b77aafa7a;hpb=77c5e19de35d9d3d9b470113e9f194ebe83b0f0b;p=casparcg diff --git a/common/memory/safe_ptr.h b/common/memory/safe_ptr.h index e4269e69b..88c184af3 100644 --- a/common/memory/safe_ptr.h +++ b/common/memory/safe_ptr.h @@ -35,8 +35,8 @@ public: safe_ptr() : impl_(std::make_shared()){} - safe_ptr(const safe_ptr& other) : impl_(other.impl_){} // noexcept - safe_ptr(safe_ptr&& other) : impl_(std::move(other.impl_)){} + safe_ptr(const safe_ptr& other) : impl_(other.impl_){} // noexcept + safe_ptr(safe_ptr&& other) : impl_(std::move(other.impl_)){} template safe_ptr(const safe_ptr& other, typename std::enable_if::value, void*>::type = 0) : impl_(other.impl_){} // noexcept @@ -86,19 +86,26 @@ public: } template - typename std::enable_if::value, safe_ptr&>::type + typename std::enable_if::type, T*>::value, safe_ptr&>::type operator=(const safe_ptr& other) { - safe_ptr temp(other); - temp.swap(*this); + safe_ptr(other).swap(*this); + return *this; + } + + template + typename std::enable_if::type, T*>::value, safe_ptr&>::type + operator=(safe_ptr&& other) + { + safe_ptr(std::move(other)).swap(*this); return *this; } template - typename std::enable_if::type, T*>::value, safe_ptr&>::type + typename std::enable_if::type, T*>::value, safe_ptr&>::type operator=(U&& impl) { - safe_ptr temp(std::forward(impl)); + safe_ptr temp(std::forward(impl)); temp.swap(*this); return *this; } @@ -127,7 +134,7 @@ public: operator const std::shared_ptr&() const { return impl_;} // noexcept template - bool owner_before(const safe_ptr& ptr){ return impl_.owner_before(ptr.impl_); } // noexcept + bool owner_before(const safe_ptr& ptr){ return impl_.owner_before(ptr.impl_); } // noexcept template bool owner_before(const std::shared_ptr& ptr){ return impl_.owner_before(ptr); } // noexcept