[Orxonox-commit 6112] r10770 - in code/branches/cpp11_v2: src/libraries/core src/libraries/core/object src/libraries/util test/util

landauf at orxonox.net landauf at orxonox.net
Sat Nov 7 14:42:14 CET 2015


Author: landauf
Date: 2015-11-07 14:42:14 +0100 (Sat, 07 Nov 2015)
New Revision: 10770

Modified:
   code/branches/cpp11_v2/src/libraries/core/ClassTreeMask.h
   code/branches/cpp11_v2/src/libraries/core/object/IteratorBase.h
   code/branches/cpp11_v2/src/libraries/core/object/StrongPtr.h
   code/branches/cpp11_v2/src/libraries/core/object/WeakPtr.h
   code/branches/cpp11_v2/src/libraries/util/SharedPtr.h
   code/branches/cpp11_v2/test/util/SharedPtrTest.cc
Log:
made conversion to bool operators explicit

Modified: code/branches/cpp11_v2/src/libraries/core/ClassTreeMask.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/core/ClassTreeMask.h	2015-11-07 09:23:42 UTC (rev 10769)
+++ code/branches/cpp11_v2/src/libraries/core/ClassTreeMask.h	2015-11-07 13:42:14 UTC (rev 10770)
@@ -151,7 +151,7 @@
             const ClassTreeMaskIterator& operator++();
             ClassTreeMaskNode* operator*() const;
             ClassTreeMaskNode* operator->() const;
-            operator bool() const;
+            explicit operator bool() const;
             bool operator==(ClassTreeMaskNode* compare) const;
             bool operator!=(ClassTreeMaskNode* compare) const;
 
@@ -288,7 +288,7 @@
             /// Returns true if the ClassTreeMaskObjectIterator doesn't point at the given object.
             inline bool operator!=(BaseObject* pointer) const { return (this->objectIterator_ && (*this->objectIterator_) != pointer) || (!this->objectIterator_ && pointer != nullptr); }
             /// Returns true if the ClassTreeMaskObjectIterator hasn't already reached the end.
-            inline operator bool() const { return (this->objectIterator_); }
+            inline explicit operator bool() const { return this->objectIterator_.operator bool(); }
             /// Returns the object the ClassTreeMaskObjectIterator currently points at.
             inline BaseObject* operator*() const { return (*this->objectIterator_); }
             /// Returns the object the ClassTreeMaskObjectIterator currently points at.

Modified: code/branches/cpp11_v2/src/libraries/core/object/IteratorBase.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/core/object/IteratorBase.h	2015-11-07 09:23:42 UTC (rev 10769)
+++ code/branches/cpp11_v2/src/libraries/core/object/IteratorBase.h	2015-11-07 13:42:14 UTC (rev 10770)
@@ -148,7 +148,7 @@
                 @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object.
                 @return True if the Iterator points to an existing object.
             */
-            inline operator bool() const
+            inline explicit operator bool() const
             {
                 return (this->element_ != nullptr);
             }

Modified: code/branches/cpp11_v2/src/libraries/core/object/StrongPtr.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/core/object/StrongPtr.h	2015-11-07 09:23:42 UTC (rev 10769)
+++ code/branches/cpp11_v2/src/libraries/core/object/StrongPtr.h	2015-11-07 13:42:14 UTC (rev 10770)
@@ -247,10 +247,10 @@
                 return *this->pointer_;
             }
 
-            /// Returns true if the wrapped pointer is nullptr.
-            inline bool operator!() const
+            /// Returns true if the pointer is not nullptr.
+            inline explicit operator bool() const
             {
-                return (this->pointer_ == nullptr);
+                return (this->pointer_ != nullptr);
             }
 
             /// Swaps the contents of two strong pointers.

Modified: code/branches/cpp11_v2/src/libraries/core/object/WeakPtr.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/core/object/WeakPtr.h	2015-11-07 09:23:42 UTC (rev 10769)
+++ code/branches/cpp11_v2/src/libraries/core/object/WeakPtr.h	2015-11-07 13:42:14 UTC (rev 10770)
@@ -182,10 +182,10 @@
                 return *this->pointer_;
             }
 
-            /// Returns true if the wrapped pointer is nullptr.
-            inline bool operator!() const
+            /// Returns true if the pointer is not nullptr.
+            inline explicit operator bool() const
             {
-                return (this->pointer_ == nullptr);
+                return (this->pointer_ != nullptr);
             }
 
             /// Swaps the contents of two weak pointers.

Modified: code/branches/cpp11_v2/src/libraries/util/SharedPtr.h
===================================================================
--- code/branches/cpp11_v2/src/libraries/util/SharedPtr.h	2015-11-07 09:23:42 UTC (rev 10769)
+++ code/branches/cpp11_v2/src/libraries/util/SharedPtr.h	2015-11-07 13:42:14 UTC (rev 10770)
@@ -310,7 +310,7 @@
             }
 
             /// Returns true if the pointer is not nullptr.
-            inline operator bool() const
+            inline explicit operator bool() const
             {
                 return (this->pointer_ != nullptr);
             }

Modified: code/branches/cpp11_v2/test/util/SharedPtrTest.cc
===================================================================
--- code/branches/cpp11_v2/test/util/SharedPtrTest.cc	2015-11-07 09:23:42 UTC (rev 10769)
+++ code/branches/cpp11_v2/test/util/SharedPtrTest.cc	2015-11-07 13:42:14 UTC (rev 10770)
@@ -144,7 +144,7 @@
 
         test = pointer;
         EXPECT_EQ(pointer, test.get());
-        EXPECT_TRUE(test);
+        EXPECT_TRUE(static_cast<bool>(test));
     }
 
     TEST(SharedPtr, Swap)




More information about the Orxonox-commit mailing list