diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 1a3f3d6482b..25002efdca7 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -809,59 +809,6 @@ constexpr inline qint64 qRound64(float d) { return d >= 0.0f ? qint64(d + 0.5f) : qint64(d - 0.5f); } #endif -namespace QTypeTraits { - -namespace detail { -template && std::is_arithmetic_v && - std::is_floating_point_v == std::is_floating_point_v && - std::is_signed_v == std::is_signed_v && - !std::is_same_v && !std::is_same_v && - !std::is_same_v && !std::is_same_v>> -struct Promoted -{ - using type = decltype(T() + U()); -}; -} - -template -using Promoted = typename detail::Promoted::type; - -} - -template -constexpr inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; } -template -constexpr inline const T &qMax(const T &a, const T &b) { return (a < b) ? b : a; } -template -constexpr inline const T &qBound(const T &min, const T &val, const T &max) -{ return qMax(min, qMin(max, val)); } -template -constexpr inline QTypeTraits::Promoted qMin(const T &a, const U &b) -{ - using P = QTypeTraits::Promoted; - P _a = a; - P _b = b; - return (_a < _b) ? _a : _b; -} -template -constexpr inline QTypeTraits::Promoted qMax(const T &a, const U &b) -{ - using P = QTypeTraits::Promoted; - P _a = a; - P _b = b; - return (_a < _b) ? _b : _a; -} -template -constexpr inline QTypeTraits::Promoted qBound(const T &min, const U &val, const T &max) -{ return qMax(min, qMin(max, val)); } -template -constexpr inline QTypeTraits::Promoted qBound(const T &min, const T &val, const U &max) -{ return qMax(min, qMin(max, val)); } -template -constexpr inline QTypeTraits::Promoted qBound(const U &min, const T &val, const T &max) -{ return qMax(min, qMin(max, val)); } - #ifndef Q_FORWARD_DECLARE_OBJC_CLASS # ifdef __OBJC__ # define Q_FORWARD_DECLARE_OBJC_CLASS(classname) @class classname @@ -1084,6 +1031,73 @@ typedef void (*QFunctionPointer)(); # define Q_UNIMPLEMENTED() qWarning("Unimplemented code.") #endif +namespace QTypeTraits { + +namespace detail { +template && std::is_arithmetic_v && + std::is_floating_point_v == std::is_floating_point_v && + std::is_signed_v == std::is_signed_v && + !std::is_same_v && !std::is_same_v && + !std::is_same_v && !std::is_same_v>> +struct Promoted +{ + using type = decltype(T() + U()); +}; +} + +template +using Promoted = typename detail::Promoted::type; + +} + +template +constexpr inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; } +template +constexpr inline const T &qMax(const T &a, const T &b) { return (a < b) ? b : a; } +template +constexpr inline const T &qBound(const T &min, const T &val, const T &max) +{ + Q_ASSERT(!(max < min)); + return qMax(min, qMin(max, val)); +} +template +constexpr inline QTypeTraits::Promoted qMin(const T &a, const U &b) +{ + using P = QTypeTraits::Promoted; + P _a = a; + P _b = b; + return (_a < _b) ? _a : _b; +} +template +constexpr inline QTypeTraits::Promoted qMax(const T &a, const U &b) +{ + using P = QTypeTraits::Promoted; + P _a = a; + P _b = b; + return (_a < _b) ? _b : _a; +} +template +constexpr inline QTypeTraits::Promoted qBound(const T &min, const U &val, const T &max) +{ + Q_ASSERT(!(max < min)); + return qMax(min, qMin(max, val)); +} +template +constexpr inline QTypeTraits::Promoted qBound(const T &min, const T &val, const U &max) +{ + using P = QTypeTraits::Promoted; + Q_ASSERT(!(P(max) < P(min))); + return qMax(min, qMin(max, val)); +} +template +constexpr inline QTypeTraits::Promoted qBound(const U &min, const T &val, const T &max) +{ + using P = QTypeTraits::Promoted; + Q_ASSERT(!(P(max) < P(min))); + return qMax(min, qMin(max, val)); +} + [[nodiscard]] constexpr bool qFuzzyCompare(double p1, double p2) { return (qAbs(p1 - p2) * 1000000000000. <= qMin(qAbs(p1), qAbs(p2)));