diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2018-07-31 15:55:36 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2018-07-31 15:55:36 +0100 |
commit | 77a6c969e9c39e1168748c17b7dc33154ae325d7 (patch) | |
tree | 5ccaaa4d5841819f98d41d03b04a4a0957b5316b | |
parent | ddf98a96d0112377361258068a167ba7e51ed345 (diff) | |
download | gcc-77a6c969e9c39e1168748c17b7dc33154ae325d7.zip gcc-77a6c969e9c39e1168748c17b7dc33154ae325d7.tar.gz gcc-77a6c969e9c39e1168748c17b7dc33154ae325d7.tar.bz2 |
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
-rw-r--r-- | libstdc++-v3/ChangeLog | 6 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/pointer.h | 4 |
2 files changed, 10 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 6298f7e..b77a9f0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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 diff --git a/libstdc++-v3/include/ext/pointer.h b/libstdc++-v3/include/ext/pointer.h index 318fbb1..ee5c30d 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 |