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
This commit is contained in:
parent
ddf98a96d0
commit
77a6c969e9
2 changed files with 10 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue