mirror of https://github.com/axmolengine/axmol.git
Merge pull request #15744 from mogemimi/fix-refptr-warnings
Fix warnings caused by comparison between RefPtr and C++11's nullptr
This commit is contained in:
commit
67c95549b3
|
@ -29,6 +29,7 @@
|
|||
|
||||
#include "base/CCRef.h"
|
||||
#include "base/ccMacros.h"
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -212,8 +213,6 @@ public:
|
|||
|
||||
inline bool operator > (typename std::remove_const<T>::type * other) const { return _ptr > other; }
|
||||
|
||||
inline bool operator > (const std::nullptr_t other) const { return _ptr > other; }
|
||||
|
||||
|
||||
inline bool operator < (const RefPtr<T> & other) const { return _ptr < other._ptr; }
|
||||
|
||||
|
@ -221,8 +220,6 @@ public:
|
|||
|
||||
inline bool operator < (typename std::remove_const<T>::type * other) const { return _ptr < other; }
|
||||
|
||||
inline bool operator < (const std::nullptr_t other) const { return _ptr < other; }
|
||||
|
||||
|
||||
inline bool operator >= (const RefPtr<T> & other) const { return _ptr >= other._ptr; }
|
||||
|
||||
|
@ -230,8 +227,6 @@ public:
|
|||
|
||||
inline bool operator >= (typename std::remove_const<T>::type * other) const { return _ptr >= other; }
|
||||
|
||||
inline bool operator >= (const std::nullptr_t other) const { return _ptr >= other; }
|
||||
|
||||
|
||||
inline bool operator <= (const RefPtr<T> & other) const { return _ptr <= other._ptr; }
|
||||
|
||||
|
@ -239,8 +234,6 @@ public:
|
|||
|
||||
inline bool operator <= (typename std::remove_const<T>::type * other) const { return _ptr <= other; }
|
||||
|
||||
inline bool operator <= (const std::nullptr_t other) const { return _ptr <= other; }
|
||||
|
||||
|
||||
inline operator bool() const { return _ptr != nullptr; }
|
||||
|
||||
|
@ -283,6 +276,54 @@ private:
|
|||
Ref * _ptr;
|
||||
};
|
||||
|
||||
template<class T> inline
|
||||
bool operator<(const RefPtr<T>& r, std::nullptr_t)
|
||||
{
|
||||
return std::less<T*>()(r.get(), nullptr);
|
||||
}
|
||||
|
||||
template<class T> inline
|
||||
bool operator<(std::nullptr_t, const RefPtr<T>& r)
|
||||
{
|
||||
return std::less<T*>()(nullptr, r.get());
|
||||
}
|
||||
|
||||
template<class T> inline
|
||||
bool operator>(const RefPtr<T>& r, std::nullptr_t)
|
||||
{
|
||||
return nullptr < r;
|
||||
}
|
||||
|
||||
template<class T> inline
|
||||
bool operator>(std::nullptr_t, const RefPtr<T>& r)
|
||||
{
|
||||
return r < nullptr;
|
||||
}
|
||||
|
||||
template<class T> inline
|
||||
bool operator<=(const RefPtr<T>& r, std::nullptr_t)
|
||||
{
|
||||
return !(nullptr < r);
|
||||
}
|
||||
|
||||
template<class T> inline
|
||||
bool operator<=(std::nullptr_t, const RefPtr<T>& r)
|
||||
{
|
||||
return !(r < nullptr);
|
||||
}
|
||||
|
||||
template<class T> inline
|
||||
bool operator>=(const RefPtr<T>& r, std::nullptr_t)
|
||||
{
|
||||
return !(r < nullptr);
|
||||
}
|
||||
|
||||
template<class T> inline
|
||||
bool operator>=(std::nullptr_t, const RefPtr<T>& r)
|
||||
{
|
||||
return !(nullptr < r);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast between RefPtr types statically.
|
||||
*/
|
||||
|
|
|
@ -264,6 +264,10 @@ void RefPtrTest::onEnter()
|
|||
CC_ASSERT(false == (ref1 > nullptr));
|
||||
CC_ASSERT(true == (ref1 <= nullptr));
|
||||
CC_ASSERT(true == (ref1 >= nullptr));
|
||||
CC_ASSERT(false == (nullptr < ref1));
|
||||
CC_ASSERT(false == (nullptr > ref1));
|
||||
CC_ASSERT(true == (nullptr <= ref1));
|
||||
CC_ASSERT(true == (nullptr >= ref1));
|
||||
|
||||
CC_ASSERT(false == (ref1 == __String::create("Hello")));
|
||||
CC_ASSERT(true == (ref1 != __String::create("Hello")));
|
||||
|
@ -280,6 +284,17 @@ void RefPtrTest::onEnter()
|
|||
CC_ASSERT(true == (ref1 > ref2));
|
||||
CC_ASSERT(false == (ref1 <= ref2));
|
||||
CC_ASSERT(true == (ref1 >= ref2));
|
||||
|
||||
CC_ASSERT(false == (ref1 == nullptr));
|
||||
CC_ASSERT(true == (ref1 != nullptr));
|
||||
CC_ASSERT(false == (ref1 < nullptr));
|
||||
CC_ASSERT(true == (ref1 > nullptr));
|
||||
CC_ASSERT(false == (ref1 <= nullptr));
|
||||
CC_ASSERT(true == (ref1 >= nullptr));
|
||||
CC_ASSERT(true == (nullptr < ref1));
|
||||
CC_ASSERT(false == (nullptr > ref1));
|
||||
CC_ASSERT(true == (nullptr <= ref1));
|
||||
CC_ASSERT(false == (nullptr >= ref1));
|
||||
}
|
||||
|
||||
// TEST(moveConstructor)
|
||||
|
|
Loading…
Reference in New Issue