From 77a6c969e9c39e1168748c17b7dc33154ae325d7 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Tue, 31 Jul 2018 15:55:36 +0100 Subject: [PATCH] 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. From-SVN: r263162 --- libstdc++-v3/ChangeLog | 6 ++++++ libstdc++-v3/include/ext/pointer.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6298f7eab23..b77a9f00bc9 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2018-07-31 Jonathan Wakely + + * include/ext/pointer.h [__cplusplus >= 201103L] + (_Pointer_adapter::operator bool): Add explicit conversion operator + to replace safe bool idiom. + 2018-07-30 Jonathan Wakely PR libstdc++/86734 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 -- 2.30.2