public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Replace safe bool idiom with explicit operator bool
@ 2018-07-31 14:55 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2018-07-31 14:55 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 197 bytes --]

	* include/ext/pointer.h [__cplusplus >= 201103L]
	(_Pointer_adapter::operator bool): Add explicit conversion operator
	to replace safe bool idiom.

Tested powerpc64le-linux, committed to trunk.



[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1192 bytes --]

commit 791062941cf5c4b93153bfd10d5bb9b0ac78d301
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jul 31 11:33:03 2018 +0100

    Replace safe bool idiom with explicit operator bool
    
            * include/ext/pointer.h [__cplusplus >= 201103L]
            (_Pointer_adapter::operator bool): Add explicit conversion operator
            to replace safe bool idiom.

diff --git a/libstdc++-v3/include/ext/pointer.h b/libstdc++-v3/include/ext/pointer.h
index 318fbb11b08..ee5c30dfa64 100644
--- a/libstdc++-v3/include/ext/pointer.h
+++ b/libstdc++-v3/include/ext/pointer.h
@@ -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 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-07-31 14:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-31 14:55 [PATCH] Replace safe bool idiom with explicit operator bool Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).