mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
fix move ctor/assignment
This commit is contained in:
@@ -47,7 +47,7 @@ class AutoPtr
|
||||
/// AutoPtr works in the following way:
|
||||
/// If an AutoPtr is assigned an ordinary pointer to
|
||||
/// an object (via the constructor or the assignment operator),
|
||||
/// it takes ownership of the object and the object's reference
|
||||
/// it takes ownership of the object and the object's reference
|
||||
/// count remains unchanged.
|
||||
/// If the AutoPtr is assigned another AutoPtr, the
|
||||
/// object's reference count is incremented by one by
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
ptr._ptr = nullptr;
|
||||
}
|
||||
|
||||
template <class Other>
|
||||
template <class Other>
|
||||
AutoPtr(const AutoPtr<Other>& ptr): _ptr(const_cast<Other*>(ptr.get()))
|
||||
{
|
||||
if (_ptr) _ptr->duplicate();
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
{
|
||||
if (_ptr) _ptr->release();
|
||||
}
|
||||
|
||||
|
||||
AutoPtr& assign(C* ptr)
|
||||
{
|
||||
if (_ptr != ptr)
|
||||
@@ -115,7 +115,7 @@ public:
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
AutoPtr& assign(const AutoPtr& ptr)
|
||||
{
|
||||
if (&ptr != this)
|
||||
@@ -126,8 +126,8 @@ public:
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Other>
|
||||
|
||||
template <class Other>
|
||||
AutoPtr& assign(const AutoPtr<Other>& ptr)
|
||||
{
|
||||
if (ptr.get() != _ptr)
|
||||
@@ -182,12 +182,12 @@ public:
|
||||
AutoPtr& operator = (AutoPtr&& ptr) noexcept
|
||||
{
|
||||
if (_ptr) _ptr->release();
|
||||
_ptr = std::move(ptr._ptr);
|
||||
_ptr = ptr._ptr;
|
||||
ptr._ptr = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Other>
|
||||
|
||||
template <class Other>
|
||||
AutoPtr& operator = (const AutoPtr<Other>& ptr)
|
||||
{
|
||||
return assign<Other>(ptr);
|
||||
@@ -197,8 +197,8 @@ public:
|
||||
{
|
||||
std::swap(_ptr, ptr._ptr);
|
||||
}
|
||||
|
||||
template <class Other>
|
||||
|
||||
template <class Other>
|
||||
AutoPtr<Other> cast() const
|
||||
/// Casts the AutoPtr via a dynamic cast to the given type.
|
||||
/// Returns an AutoPtr containing NULL if the cast fails.
|
||||
@@ -211,7 +211,7 @@ public:
|
||||
return AutoPtr<Other>(pOther, true);
|
||||
}
|
||||
|
||||
template <class Other>
|
||||
template <class Other>
|
||||
AutoPtr<Other> unsafeCast() const
|
||||
/// Casts the AutoPtr via a static cast to the given type.
|
||||
/// Example: (assume class Sub: public Super)
|
||||
@@ -269,12 +269,12 @@ public:
|
||||
{
|
||||
return _ptr;
|
||||
}
|
||||
|
||||
|
||||
operator const C* () const
|
||||
{
|
||||
return _ptr;
|
||||
}
|
||||
|
||||
|
||||
bool operator ! () const
|
||||
{
|
||||
return _ptr == nullptr;
|
||||
@@ -284,7 +284,7 @@ public:
|
||||
{
|
||||
return _ptr == nullptr;
|
||||
}
|
||||
|
||||
|
||||
C* duplicate()
|
||||
{
|
||||
if (_ptr) _ptr->duplicate();
|
||||
|
||||
Reference in New Issue
Block a user