Make QRect(F) and QMargins comparison operators hidden friends
Hide them from ADL to reduce noise. QRect operators were already implemented as hidden friends, but a left-over declaration un-hid them again. Use the opportunity to simplify QMargins::operator!= by just inverting operator==. No need to spell things out, the compiler can do that for us. Change-Id: I55722223a2267cbeba5726dc912b48d6e017e580 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
parent
525372c567
commit
feda3e7673
@ -143,15 +143,13 @@ QT_BEGIN_NAMESPACE
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool operator==(const QMargins &m1, const QMargins &m2)
|
\fn bool QMargins::operator==(const QMargins &m1, const QMargins &m2)
|
||||||
\relates QMargins
|
|
||||||
|
|
||||||
Returns \c true if \a m1 and \a m2 are equal; otherwise returns \c false.
|
Returns \c true if \a m1 and \a m2 are equal; otherwise returns \c false.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool operator!=(const QMargins &m1, const QMargins &m2)
|
\fn bool QMargins::operator!=(const QMargins &m1, const QMargins &m2)
|
||||||
\relates QMargins
|
|
||||||
|
|
||||||
Returns \c true if \a m1 and \a m2 are different; otherwise returns \c false.
|
Returns \c true if \a m1 and \a m2 are different; otherwise returns \c false.
|
||||||
*/
|
*/
|
||||||
@ -566,15 +564,13 @@ QDebug operator<<(QDebug dbg, const QMargins &m)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool operator==(const QMarginsF &lhs, const QMarginsF &rhs)
|
\fn bool QMarginsF::operator==(const QMarginsF &lhs, const QMarginsF &rhs)
|
||||||
\relates QMarginsF
|
|
||||||
|
|
||||||
Returns \c true if \a lhs and \a rhs are equal; otherwise returns \c false.
|
Returns \c true if \a lhs and \a rhs are equal; otherwise returns \c false.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs)
|
\fn bool QMarginsF::operator!=(const QMarginsF &lhs, const QMarginsF &rhs)
|
||||||
\relates QMarginsF
|
|
||||||
|
|
||||||
Returns \c true if \a lhs and \a rhs are different; otherwise returns \c false.
|
Returns \c true if \a lhs and \a rhs are different; otherwise returns \c false.
|
||||||
*/
|
*/
|
||||||
|
@ -81,8 +81,19 @@ private:
|
|||||||
int m_right;
|
int m_right;
|
||||||
int m_bottom;
|
int m_bottom;
|
||||||
|
|
||||||
friend constexpr inline bool operator==(const QMargins &, const QMargins &) noexcept;
|
friend constexpr inline bool operator==(const QMargins &m1, const QMargins &m2) noexcept
|
||||||
friend constexpr inline bool operator!=(const QMargins &, const QMargins &) noexcept;
|
{
|
||||||
|
return
|
||||||
|
m1.m_left == m2.m_left &&
|
||||||
|
m1.m_top == m2.m_top &&
|
||||||
|
m1.m_right == m2.m_right &&
|
||||||
|
m1.m_bottom == m2.m_bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend constexpr inline bool operator!=(const QMargins &m1, const QMargins &m2) noexcept
|
||||||
|
{
|
||||||
|
return !(m1 == m2);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_TYPEINFO(QMargins, Q_MOVABLE_TYPE);
|
Q_DECLARE_TYPEINFO(QMargins, Q_MOVABLE_TYPE);
|
||||||
@ -132,24 +143,6 @@ constexpr inline void QMargins::setRight(int aright) noexcept
|
|||||||
constexpr inline void QMargins::setBottom(int abottom) noexcept
|
constexpr inline void QMargins::setBottom(int abottom) noexcept
|
||||||
{ m_bottom = abottom; }
|
{ m_bottom = abottom; }
|
||||||
|
|
||||||
constexpr inline bool operator==(const QMargins &m1, const QMargins &m2) noexcept
|
|
||||||
{
|
|
||||||
return
|
|
||||||
m1.m_left == m2.m_left &&
|
|
||||||
m1.m_top == m2.m_top &&
|
|
||||||
m1.m_right == m2.m_right &&
|
|
||||||
m1.m_bottom == m2.m_bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr inline bool operator!=(const QMargins &m1, const QMargins &m2) noexcept
|
|
||||||
{
|
|
||||||
return
|
|
||||||
m1.m_left != m2.m_left ||
|
|
||||||
m1.m_top != m2.m_top ||
|
|
||||||
m1.m_right != m2.m_right ||
|
|
||||||
m1.m_bottom != m2.m_bottom;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr inline QMargins operator+(const QMargins &m1, const QMargins &m2) noexcept
|
constexpr inline QMargins operator+(const QMargins &m1, const QMargins &m2) noexcept
|
||||||
{
|
{
|
||||||
return QMargins(m1.left() + m2.left(), m1.top() + m2.top(),
|
return QMargins(m1.left() + m2.left(), m1.top() + m2.top(),
|
||||||
@ -321,6 +314,19 @@ private:
|
|||||||
qreal m_top;
|
qreal m_top;
|
||||||
qreal m_right;
|
qreal m_right;
|
||||||
qreal m_bottom;
|
qreal m_bottom;
|
||||||
|
|
||||||
|
friend constexpr inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
|
||||||
|
{
|
||||||
|
return qFuzzyCompare(lhs.left(), rhs.left())
|
||||||
|
&& qFuzzyCompare(lhs.top(), rhs.top())
|
||||||
|
&& qFuzzyCompare(lhs.right(), rhs.right())
|
||||||
|
&& qFuzzyCompare(lhs.bottom(), rhs.bottom());
|
||||||
|
}
|
||||||
|
|
||||||
|
friend constexpr inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
|
||||||
|
{
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_TYPEINFO(QMarginsF, Q_MOVABLE_TYPE);
|
Q_DECLARE_TYPEINFO(QMarginsF, Q_MOVABLE_TYPE);
|
||||||
@ -375,19 +381,6 @@ constexpr inline void QMarginsF::setRight(qreal aright) noexcept
|
|||||||
constexpr inline void QMarginsF::setBottom(qreal abottom) noexcept
|
constexpr inline void QMarginsF::setBottom(qreal abottom) noexcept
|
||||||
{ m_bottom = abottom; }
|
{ m_bottom = abottom; }
|
||||||
|
|
||||||
constexpr inline bool operator==(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
|
|
||||||
{
|
|
||||||
return qFuzzyCompare(lhs.left(), rhs.left())
|
|
||||||
&& qFuzzyCompare(lhs.top(), rhs.top())
|
|
||||||
&& qFuzzyCompare(lhs.right(), rhs.right())
|
|
||||||
&& qFuzzyCompare(lhs.bottom(), rhs.bottom());
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr inline bool operator!=(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
|
|
||||||
{
|
|
||||||
return !operator==(lhs, rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
|
constexpr inline QMarginsF operator+(const QMarginsF &lhs, const QMarginsF &rhs) noexcept
|
||||||
{
|
{
|
||||||
return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(),
|
return QMarginsF(lhs.left() + rhs.left(), lhs.top() + rhs.top(),
|
||||||
|
@ -1141,8 +1141,7 @@ bool QRect::intersects(const QRect &r) const noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool operator==(const QRect &r1, const QRect &r2)
|
\fn bool QRect::operator==(const QRect &r1, const QRect &r2)
|
||||||
\relates QRect
|
|
||||||
|
|
||||||
Returns \c true if the rectangles \a r1 and \a r2 are equal,
|
Returns \c true if the rectangles \a r1 and \a r2 are equal,
|
||||||
otherwise returns \c false.
|
otherwise returns \c false.
|
||||||
@ -1150,8 +1149,7 @@ bool QRect::intersects(const QRect &r) const noexcept
|
|||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool operator!=(const QRect &r1, const QRect &r2)
|
\fn bool QRect::operator!=(const QRect &r1, const QRect &r2)
|
||||||
\relates QRect
|
|
||||||
|
|
||||||
Returns \c true if the rectangles \a r1 and \a r2 are different, otherwise
|
Returns \c true if the rectangles \a r1 and \a r2 are different, otherwise
|
||||||
returns \c false.
|
returns \c false.
|
||||||
@ -2368,8 +2366,7 @@ QRect QRectF::toAlignedRect() const noexcept
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool operator==(const QRectF &r1, const QRectF &r2)
|
\fn bool QRectF::operator==(const QRectF &r1, const QRectF &r2)
|
||||||
\relates QRectF
|
|
||||||
|
|
||||||
Returns \c true if the rectangles \a r1 and \a r2 are \b approximately equal,
|
Returns \c true if the rectangles \a r1 and \a r2 are \b approximately equal,
|
||||||
otherwise returns \c false.
|
otherwise returns \c false.
|
||||||
@ -2382,8 +2379,7 @@ QRect QRectF::toAlignedRect() const noexcept
|
|||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool operator!=(const QRectF &r1, const QRectF &r2)
|
\fn bool QRectF::operator!=(const QRectF &r1, const QRectF &r2)
|
||||||
\relates QRectF
|
|
||||||
|
|
||||||
Returns \c true if the rectangles \a r1 and \a r2 are sufficiently
|
Returns \c true if the rectangles \a r1 and \a r2 are sufficiently
|
||||||
different, otherwise returns \c false.
|
different, otherwise returns \c false.
|
||||||
|
@ -166,9 +166,6 @@ private:
|
|||||||
};
|
};
|
||||||
Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE);
|
Q_DECLARE_TYPEINFO(QRect, Q_MOVABLE_TYPE);
|
||||||
|
|
||||||
constexpr inline bool operator==(const QRect &, const QRect &) noexcept;
|
|
||||||
constexpr inline bool operator!=(const QRect &, const QRect &) noexcept;
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
QRect stream functions
|
QRect stream functions
|
||||||
@ -630,9 +627,6 @@ private:
|
|||||||
};
|
};
|
||||||
Q_DECLARE_TYPEINFO(QRectF, Q_MOVABLE_TYPE);
|
Q_DECLARE_TYPEINFO(QRectF, Q_MOVABLE_TYPE);
|
||||||
|
|
||||||
constexpr inline bool operator==(const QRectF &, const QRectF &) noexcept;
|
|
||||||
constexpr inline bool operator!=(const QRectF &, const QRectF &) noexcept;
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
QRectF stream functions
|
QRectF stream functions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user