Replace safe bool idiom with explicit operator bool
authorJonathan Wakely <jwakely@redhat.com>
Tue, 31 Jul 2018 14:55:36 +0000 (15:55 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 31 Jul 2018 14:55:36 +0000 (15:55 +0100)
* include/ext/pointer.h [__cplusplus >= 201103L]
(_Pointer_adapter::operator bool): Add explicit conversion operator
to replace safe bool idiom.

From-SVN: r263162

libstdc++-v3/ChangeLog
libstdc++-v3/include/ext/pointer.h

index 6298f7eab23cf4164503d6670940a6c860c22a41..b77a9f00bc9b7e548b258831d7710460e311c03d 100644 (file)
@@ -1,3 +1,9 @@
+2018-07-31  Jonathan Wakely  <jwakely@redhat.com>
+
+       * include/ext/pointer.h [__cplusplus >= 201103L]
+       (_Pointer_adapter::operator bool): Add explicit conversion operator
+       to replace safe bool idiom.
+
 2018-07-30  Jonathan Wakely  <jwakely@redhat.com>
 
        PR libstdc++/86734
index 318fbb11b087ffaff88e3d6b9300913a705aeb30..ee5c30dfa64fc5baa0cd9b2156615f37bcb5f2c1 100644 (file)
@@ -356,6 +356,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return _Storage_policy::get()[__index]; }
 
       // To allow implicit conversion to "bool", for "if (ptr)..."
+#if __cplusplus >= 201103L
+      explicit operator bool() const { return _Storage_policy::get() != 0; }
+#else
     private:
       typedef element_type*(_Pointer_adapter::*__unspecified_bool_type)() const;
 
@@ -370,6 +373,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       inline bool
       operator!() const 
       { return (_Storage_policy::get() == 0); }
+#endif
   
       // Pointer differences
       inline friend std::ptrdiff_t