From 5896652d4db8c6bb4d8b4a67ab616e36ccd6a74b Mon Sep 17 00:00:00 2001 From: rani_sharoni Date: Sun, 14 Mar 2004 16:41:35 +0000 Subject: [PATCH] fix SmartPtr conversion issues git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@134 7ec92016-0320-0410-acc4-a06ded1c099a --- Reference/SmartPtr.h | 59 +++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/Reference/SmartPtr.h b/Reference/SmartPtr.h index fa30ea3..5234aba 100644 --- a/Reference/SmartPtr.h +++ b/Reference/SmartPtr.h @@ -926,21 +926,6 @@ namespace Loki bool operator!() const // Enables "if (!sp) ..." { return GetImpl(*this) == 0; } - inline friend bool operator==(const SmartPtr& lhs, - const T* rhs) - { return GetImpl(lhs) == rhs; } - - inline friend bool operator==(const T* lhs, - const SmartPtr& rhs) - { return rhs == lhs; } - - inline friend bool operator!=(const SmartPtr& lhs, - const T* rhs) - { return !(lhs == rhs); } - - inline friend bool operator!=(const T* lhs, - const SmartPtr& rhs) - { return rhs != lhs; } // Ambiguity buster template @@ -952,7 +937,7 @@ namespace Loki template class SP1 > bool operator==(const SmartPtr& rhs) const - { return *this == GetImpl(rhs); } + { return GetImpl(*this) == GetImpl(rhs); } // Ambiguity buster template @@ -976,24 +961,26 @@ namespace Loki template class SP1 > bool operator<(const SmartPtr& rhs) const - { return *this < GetImpl(rhs); } + { return GetImpl(*this) < GetImpl(rhs); } private: // Helper for enabling 'if (sp)' struct Tester { - Tester() {} - private: - void operator delete(void*); + Tester(int) {} + void dummy() {} }; + typedef void (Tester::*unspecified_boolean_type_)(); + + typedef typename Select::Result + unspecified_boolean_type; + public: // enable 'if (sp)' - operator Tester*() const + operator unspecified_boolean_type() const { - if (!*this) return 0; - static Tester t; - return &t; + return !*this ? 0 : &Tester::dummy; } private: @@ -1029,7 +1016,7 @@ namespace Loki typename U > inline bool operator==(const SmartPtr& lhs, - const U* rhs) + U* rhs) { return GetImpl(lhs) == rhs; } //////////////////////////////////////////////////////////////////////////////// @@ -1045,7 +1032,7 @@ namespace Loki template class SP, typename U > - inline bool operator==(const U* lhs, + inline bool operator==(U* lhs, const SmartPtr& rhs) { return rhs == lhs; } @@ -1063,7 +1050,7 @@ namespace Loki typename U > inline bool operator!=(const SmartPtr& lhs, - const U* rhs) + U* rhs) { return !(lhs == rhs); } //////////////////////////////////////////////////////////////////////////////// @@ -1079,7 +1066,7 @@ namespace Loki template class SP, typename U > - inline bool operator!=(const U* lhs, + inline bool operator!=(U* lhs, const SmartPtr& rhs) { return rhs != lhs; } @@ -1097,7 +1084,7 @@ namespace Loki typename U > inline bool operator<(const SmartPtr& lhs, - const U* rhs); + U* rhs); //////////////////////////////////////////////////////////////////////////////// // operator< for lhs = raw pointer, rhs = SmartPtr -- NOT DEFINED @@ -1112,7 +1099,7 @@ namespace Loki template class SP, typename U > - inline bool operator<(const U* lhs, + inline bool operator<(U* lhs, const SmartPtr& rhs); //////////////////////////////////////////////////////////////////////////////// @@ -1129,7 +1116,7 @@ namespace Loki typename U > inline bool operator>(const SmartPtr& lhs, - const U* rhs) + U* rhs) { return rhs < lhs; } //////////////////////////////////////////////////////////////////////////////// @@ -1145,7 +1132,7 @@ namespace Loki template class SP, typename U > - inline bool operator>(const U* lhs, + inline bool operator>(U* lhs, const SmartPtr& rhs) { return rhs < lhs; } @@ -1163,7 +1150,7 @@ namespace Loki typename U > inline bool operator<=(const SmartPtr& lhs, - const U* rhs) + U* rhs) { return !(rhs < lhs); } //////////////////////////////////////////////////////////////////////////////// @@ -1179,7 +1166,7 @@ namespace Loki template class SP, typename U > - inline bool operator<=(const U* lhs, + inline bool operator<=(U* lhs, const SmartPtr& rhs) { return !(rhs < lhs); } @@ -1197,7 +1184,7 @@ namespace Loki typename U > inline bool operator>=(const SmartPtr& lhs, - const U* rhs) + U* rhs) { return !(lhs < rhs); } //////////////////////////////////////////////////////////////////////////////// @@ -1213,7 +1200,7 @@ namespace Loki template class SP, typename U > - inline bool operator>=(const U* lhs, + inline bool operator>=(U* lhs, const SmartPtr& rhs) { return !(lhs < rhs); }