mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 18:42:41 +01:00
AutoPtr and SharedPtr comparison with nullptr
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@@ -306,6 +307,11 @@ public:
|
|||||||
return _ptr == ptr;
|
return _ptr == ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator == (std::nullptr_t ptr) const
|
||||||
|
{
|
||||||
|
return _ptr == ptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator != (const AutoPtr& ptr) const
|
bool operator != (const AutoPtr& ptr) const
|
||||||
{
|
{
|
||||||
return _ptr != ptr._ptr;
|
return _ptr != ptr._ptr;
|
||||||
@@ -321,6 +327,11 @@ public:
|
|||||||
return _ptr != ptr;
|
return _ptr != ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator != (std::nullptr_t ptr) const
|
||||||
|
{
|
||||||
|
return _ptr != ptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator < (const AutoPtr& ptr) const
|
bool operator < (const AutoPtr& ptr) const
|
||||||
{
|
{
|
||||||
return _ptr < ptr._ptr;
|
return _ptr < ptr._ptr;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include "Poco/AtomicCounter.h"
|
#include "Poco/AtomicCounter.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
|
||||||
namespace Poco {
|
namespace Poco {
|
||||||
@@ -336,6 +337,11 @@ public:
|
|||||||
return get() == ptr;
|
return get() == ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator == (std::nullptr_t ptr) const
|
||||||
|
{
|
||||||
|
return get() == ptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator != (const SharedPtr& ptr) const
|
bool operator != (const SharedPtr& ptr) const
|
||||||
{
|
{
|
||||||
return get() != ptr.get();
|
return get() != ptr.get();
|
||||||
@@ -351,6 +357,11 @@ public:
|
|||||||
return get() != ptr;
|
return get() != ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator != (std::nullptr_t ptr) const
|
||||||
|
{
|
||||||
|
return get() != ptr;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator < (const SharedPtr& ptr) const
|
bool operator < (const SharedPtr& ptr) const
|
||||||
{
|
{
|
||||||
return get() < ptr.get();
|
return get() < ptr.get();
|
||||||
|
|||||||
@@ -179,6 +179,9 @@ void AutoPtrTest::testOps()
|
|||||||
assertTrue (!(!ptr1));
|
assertTrue (!(!ptr1));
|
||||||
ptr1 = 0;
|
ptr1 = 0;
|
||||||
assertTrue (!ptr1);
|
assertTrue (!ptr1);
|
||||||
|
|
||||||
|
assertTrue (ptr1 == nullptr);
|
||||||
|
assertTrue (ptr2 != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,10 @@ void SharedPtrTest::testSharedPtr()
|
|||||||
{
|
{
|
||||||
SharedPtr<TestObject> ptr1;
|
SharedPtr<TestObject> ptr1;
|
||||||
assertNull(ptr1.get());
|
assertNull(ptr1.get());
|
||||||
|
assertTrue (ptr1 == nullptr);
|
||||||
|
|
||||||
TestObject* pTO1 = new TestObject("one");
|
TestObject* pTO1 = new TestObject("one");
|
||||||
|
|
||||||
TestObject* pTO2 = new TestObject("two");
|
TestObject* pTO2 = new TestObject("two");
|
||||||
if (pTO2 < pTO1)
|
if (pTO2 < pTO1)
|
||||||
{
|
{
|
||||||
@@ -93,6 +96,8 @@ void SharedPtrTest::testSharedPtr()
|
|||||||
}
|
}
|
||||||
assertTrue (pTO1 < pTO2);
|
assertTrue (pTO1 < pTO2);
|
||||||
ptr1 = pTO1;
|
ptr1 = pTO1;
|
||||||
|
assertTrue (ptr1 != nullptr);
|
||||||
|
|
||||||
assertTrue (ptr1.referenceCount() == 1);
|
assertTrue (ptr1.referenceCount() == 1);
|
||||||
SharedPtr<TestObject> ptr2 = pTO2;
|
SharedPtr<TestObject> ptr2 = pTO2;
|
||||||
SharedPtr<TestObject> ptr3 = ptr1;
|
SharedPtr<TestObject> ptr3 = ptr1;
|
||||||
|
|||||||
Reference in New Issue
Block a user