mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 10:32:57 +01:00
fix move ctor/assignment
This commit is contained in:
parent
18adb1e43b
commit
eeb64cc340
@ -182,7 +182,7 @@ public:
|
||||
AutoPtr& operator = (AutoPtr&& ptr) noexcept
|
||||
{
|
||||
if (_ptr) _ptr->release();
|
||||
_ptr = std::move(ptr._ptr);
|
||||
_ptr = ptr._ptr;
|
||||
ptr._ptr = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public:
|
||||
Nullable& assign(C&& value)
|
||||
/// Assigns a value to the Nullable.
|
||||
{
|
||||
_value = value;
|
||||
_value = std::move(value);
|
||||
_isNull = false;
|
||||
return *this;
|
||||
}
|
||||
@ -152,7 +152,7 @@ public:
|
||||
Nullable& operator = (C&& value)
|
||||
/// Move-assigns a value to the Nullable.
|
||||
{
|
||||
return assign(value);
|
||||
return assign(std::move(value));
|
||||
}
|
||||
|
||||
Nullable& operator = (const Nullable& other)
|
||||
|
@ -105,7 +105,7 @@ public:
|
||||
Optional& assign(C&& value)
|
||||
/// Moves a value into the Optional.
|
||||
{
|
||||
_value = value;
|
||||
_value = std::move(value);
|
||||
_isSpecified = true;
|
||||
return *this;
|
||||
}
|
||||
@ -125,7 +125,7 @@ public:
|
||||
|
||||
Optional& operator = (C&& value)
|
||||
{
|
||||
return assign(value);
|
||||
return assign(std::move(value));
|
||||
}
|
||||
|
||||
Optional& operator = (const Optional& other)
|
||||
|
@ -61,7 +61,7 @@ class ReleasePolicy
|
||||
/// simply uses the delete operator to delete an object.
|
||||
{
|
||||
public:
|
||||
static void release(C* pObj)
|
||||
static void release(C* pObj) noexcept
|
||||
/// Delete the object.
|
||||
/// Note that pObj can be nullptr.
|
||||
{
|
||||
@ -75,7 +75,7 @@ class ReleaseArrayPolicy
|
||||
/// The release policy for SharedPtr holding arrays.
|
||||
{
|
||||
public:
|
||||
static void release(C* pObj)
|
||||
static void release(C* pObj) noexcept
|
||||
/// Delete the object.
|
||||
/// Note that pObj can be nullptr.
|
||||
{
|
||||
@ -115,7 +115,9 @@ class SharedPtr
|
||||
public:
|
||||
typedef C Type;
|
||||
|
||||
SharedPtr(): _pCounter(nullptr), _ptr(nullptr)
|
||||
SharedPtr():
|
||||
_pCounter(nullptr),
|
||||
_ptr(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -131,33 +133,32 @@ public:
|
||||
}
|
||||
|
||||
template <class Other, class OtherRP>
|
||||
SharedPtr(const SharedPtr<Other, RC, OtherRP>& ptr): _pCounter(ptr._pCounter), _ptr(const_cast<Other*>(ptr.get()))
|
||||
SharedPtr(const SharedPtr<Other, RC, OtherRP>& ptr):
|
||||
_pCounter(ptr._pCounter),
|
||||
_ptr(const_cast<Other*>(ptr.get()))
|
||||
{
|
||||
if (_pCounter) _pCounter->duplicate();
|
||||
}
|
||||
|
||||
SharedPtr(const SharedPtr& ptr): _pCounter(ptr._pCounter), _ptr(ptr._ptr)
|
||||
SharedPtr(const SharedPtr& ptr):
|
||||
_pCounter(ptr._pCounter),
|
||||
_ptr(ptr._ptr)
|
||||
{
|
||||
if (_pCounter) _pCounter->duplicate();
|
||||
}
|
||||
|
||||
SharedPtr(SharedPtr&& ptr) noexcept: _pCounter(std::move(ptr._pCounter)), _ptr(std::move(ptr._ptr))
|
||||
SharedPtr(SharedPtr&& ptr) noexcept:
|
||||
_pCounter(ptr._pCounter),
|
||||
_ptr(ptr._ptr)
|
||||
{
|
||||
ptr._pCounter = nullptr;
|
||||
ptr._ptr = nullptr;
|
||||
}
|
||||
|
||||
~SharedPtr()
|
||||
{
|
||||
try
|
||||
{
|
||||
release();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
poco_unexpected();
|
||||
}
|
||||
}
|
||||
|
||||
SharedPtr& assign(C* ptr)
|
||||
{
|
||||
@ -223,9 +224,10 @@ public:
|
||||
|
||||
SharedPtr& operator = (SharedPtr&& ptr) noexcept
|
||||
{
|
||||
_ptr = std::move(ptr._ptr);
|
||||
_pCounter = std::move(ptr._pCounter);
|
||||
release();
|
||||
_ptr = ptr._ptr;
|
||||
ptr._ptr = nullptr;
|
||||
_pCounter = ptr._pCounter;
|
||||
ptr._pCounter = nullptr;
|
||||
return *this;
|
||||
}
|
||||
@ -423,7 +425,7 @@ private:
|
||||
return _ptr;
|
||||
}
|
||||
|
||||
void release()
|
||||
void release() noexcept
|
||||
{
|
||||
if (_pCounter && _pCounter->release() == 0)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user