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