Smart pointers: port to explicit operator bool
Enough with the restricted bool trick; use the established solution. [ChangeLog][Potentially Source-Incompatible Changes] QScopedPointer, QSharedPointer and QWeakPointer's conversion operator towards bool is now explicit. In some cases this may require an explicit cast towards bool that was not needed before (notably, when returning an object of these types from a function that actually returns bool). Change-Id: I02b89278e75b7e7493ee7e35460504719e00f028 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
8dd50ef206
commit
67c3c7a29c
@ -95,7 +95,6 @@ typedef QScopedPointerObjectDeleteLater<QObject> QScopedPointerDeleteLater;
|
|||||||
template <typename T, typename Cleanup = QScopedPointerDeleter<T> >
|
template <typename T, typename Cleanup = QScopedPointerDeleter<T> >
|
||||||
class QScopedPointer
|
class QScopedPointer
|
||||||
{
|
{
|
||||||
typedef T *QScopedPointer:: *RestrictedBool;
|
|
||||||
public:
|
public:
|
||||||
explicit QScopedPointer(T *p = nullptr) noexcept : d(p)
|
explicit QScopedPointer(T *p = nullptr) noexcept : d(p)
|
||||||
{
|
{
|
||||||
@ -123,17 +122,10 @@ public:
|
|||||||
return !d;
|
return !d;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(Q_QDOC)
|
explicit operator bool() const
|
||||||
inline operator bool() const
|
|
||||||
{
|
{
|
||||||
return isNull() ? nullptr : &QScopedPointer::d;
|
return !isNull();
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
operator RestrictedBool() const noexcept
|
|
||||||
{
|
|
||||||
return isNull() ? nullptr : &QScopedPointer::d;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
T *data() const noexcept
|
T *data() const noexcept
|
||||||
{
|
{
|
||||||
|
@ -283,7 +283,6 @@ namespace QtSharedPointer {
|
|||||||
|
|
||||||
template <class T> class QSharedPointer
|
template <class T> class QSharedPointer
|
||||||
{
|
{
|
||||||
typedef T *QSharedPointer:: *RestrictedBool;
|
|
||||||
typedef QtSharedPointer::ExternalRefCountData Data;
|
typedef QtSharedPointer::ExternalRefCountData Data;
|
||||||
template <typename X>
|
template <typename X>
|
||||||
using IfCompatible = typename std::enable_if<std::is_convertible<X*, T*>::value, bool>::type;
|
using IfCompatible = typename std::enable_if<std::is_convertible<X*, T*>::value, bool>::type;
|
||||||
@ -301,7 +300,7 @@ public:
|
|||||||
T *data() const noexcept { return value; }
|
T *data() const noexcept { return value; }
|
||||||
T *get() const noexcept { return value; }
|
T *get() const noexcept { return value; }
|
||||||
bool isNull() const noexcept { return !data(); }
|
bool isNull() const noexcept { return !data(); }
|
||||||
operator RestrictedBool() const noexcept { return isNull() ? nullptr : &QSharedPointer::value; }
|
explicit operator bool() const noexcept { return !isNull(); }
|
||||||
bool operator !() const noexcept { return isNull(); }
|
bool operator !() const noexcept { return isNull(); }
|
||||||
T &operator*() const { return *data(); }
|
T &operator*() const { return *data(); }
|
||||||
T *operator->() const noexcept { return data(); }
|
T *operator->() const noexcept { return data(); }
|
||||||
@ -539,7 +538,6 @@ public:
|
|||||||
template <class T>
|
template <class T>
|
||||||
class QWeakPointer
|
class QWeakPointer
|
||||||
{
|
{
|
||||||
typedef T *QWeakPointer:: *RestrictedBool;
|
|
||||||
typedef QtSharedPointer::ExternalRefCountData Data;
|
typedef QtSharedPointer::ExternalRefCountData Data;
|
||||||
template <typename X>
|
template <typename X>
|
||||||
using IfCompatible = typename std::enable_if<std::is_convertible<X*, T*>::value, bool>::type;
|
using IfCompatible = typename std::enable_if<std::is_convertible<X*, T*>::value, bool>::type;
|
||||||
@ -554,7 +552,7 @@ public:
|
|||||||
typedef qptrdiff difference_type;
|
typedef qptrdiff difference_type;
|
||||||
|
|
||||||
bool isNull() const noexcept { return d == nullptr || d->strongref.loadRelaxed() == 0 || value == nullptr; }
|
bool isNull() const noexcept { return d == nullptr || d->strongref.loadRelaxed() == 0 || value == nullptr; }
|
||||||
operator RestrictedBool() const noexcept { return isNull() ? nullptr : &QWeakPointer::value; }
|
explicit operator bool() const noexcept { return !isNull(); }
|
||||||
bool operator !() const noexcept { return isNull(); }
|
bool operator !() const noexcept { return isNull(); }
|
||||||
|
|
||||||
#if QT_DEPRECATED_SINCE(5, 14)
|
#if QT_DEPRECATED_SINCE(5, 14)
|
||||||
|
@ -440,7 +440,7 @@ bool QOpenGLTextureBlitter::create()
|
|||||||
bool QOpenGLTextureBlitter::isCreated() const
|
bool QOpenGLTextureBlitter::isCreated() const
|
||||||
{
|
{
|
||||||
Q_D(const QOpenGLTextureBlitter);
|
Q_D(const QOpenGLTextureBlitter);
|
||||||
return d->programs[QOpenGLTextureBlitterPrivate::TEXTURE_2D].glProgram;
|
return !d->programs[QOpenGLTextureBlitterPrivate::TEXTURE_2D].glProgram.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -80,7 +80,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
QWindowsDialogHelperBase() = default;
|
QWindowsDialogHelperBase() = default;
|
||||||
QWindowsNativeDialogBase *nativeDialog() const;
|
QWindowsNativeDialogBase *nativeDialog() const;
|
||||||
inline bool hasNativeDialog() const { return m_nativeDialog; }
|
inline bool hasNativeDialog() const { return !m_nativeDialog.isNull(); }
|
||||||
void timerEvent(QTimerEvent *) override;
|
void timerEvent(QTimerEvent *) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user