added additional move constructor and assignment operators

This commit is contained in:
Günter Obiltschnig 2017-11-13 19:37:05 +01:00
parent e12458a63a
commit af218a8ac0
2 changed files with 32 additions and 0 deletions

View File

@ -22,6 +22,7 @@
#include "Poco/Exception.h"
#include <memory>
#include <algorithm>
#include <utility>
namespace Poco {
@ -71,6 +72,11 @@ public:
{
}
SharedPtr(std::shared_ptr<C>&& ptr):
_ptr(std::move(ptr))
{
}
~SharedPtr()
{
}
@ -118,6 +124,18 @@ public:
return assign<Other>(ptr);
}
SharedPtr& operator = (SharedPtr&& ptr)
{
_ptr = std::move(ptr._ptr);
return *this;
}
SharedPtr& operator = (std::shared_ptr<C>&& ptr)
{
_ptr = std::move(ptr);
return *this;
}
void swap(SharedPtr& ptr)
{
std::swap(_ptr, ptr._ptr);

View File

@ -161,6 +161,20 @@ void SharedPtrTest::testSharedPtr()
std::shared_ptr<TestObject> stdp2 = ptr5;
assert (stdp == stdp2);
std::shared_ptr<TestObject> stdp3(std::make_shared<TestObject>(""));
TestObject* rptr = stdp3.get();
Poco::SharedPtr<TestObject> ptr6(std::move(stdp3));
assert (!stdp3);
assert (ptr6.get() == rptr);
std::shared_ptr<TestObject> stdp4(std::make_shared<TestObject>(""));
rptr = stdp4.get();
ptr6 = std::move(stdp4);
assert (!stdp4);
assert (ptr6.get() == rptr);
}