mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-09 11:17:31 +01:00
added additional move constructor and assignment operators
This commit is contained in:
parent
e12458a63a
commit
af218a8ac0
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user