File indexing completed on 2026-09-23 09:21:55
0001
0002
0003
0004
0005 #ifndef QMINMAX_H
0006 #define QMINMAX_H
0007
0008 #if 0
0009 #pragma qt_class(QtMinMax)
0010 #pragma qt_sync_stop_processing
0011 #endif
0012
0013 #include <QtCore/qassert.h>
0014 #include <QtCore/qtconfigmacros.h>
0015 #include <QtCore/qttypetraits.h>
0016
0017 QT_BEGIN_NAMESPACE
0018
0019 template <typename T>
0020 constexpr inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; }
0021 template <typename T>
0022 constexpr inline const T &qMax(const T &a, const T &b) { return (a < b) ? b : a; }
0023 template <typename T>
0024 constexpr inline const T &qBound(const T &min, const T &val, const T &max)
0025 {
0026 Q_ASSERT(!(max < min));
0027 return qMax(min, qMin(max, val));
0028 }
0029 template <typename T, typename U>
0030 constexpr inline QTypeTraits::Promoted<T, U> qMin(const T &a, const U &b)
0031 {
0032 using P = QTypeTraits::Promoted<T, U>;
0033 P _a = a;
0034 P _b = b;
0035 return (_a < _b) ? _a : _b;
0036 }
0037 template <typename T, typename U>
0038 constexpr inline QTypeTraits::Promoted<T, U> qMax(const T &a, const U &b)
0039 {
0040 using P = QTypeTraits::Promoted<T, U>;
0041 P _a = a;
0042 P _b = b;
0043 return (_a < _b) ? _b : _a;
0044 }
0045 template <typename T, typename U>
0046 constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const U &val, const T &max)
0047 {
0048 Q_ASSERT(!(max < min));
0049 return qMax(min, qMin(max, val));
0050 }
0051 template <typename T, typename U>
0052 constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const T &val, const U &max)
0053 {
0054 using P = QTypeTraits::Promoted<T, U>;
0055 Q_ASSERT(!(P(max) < P(min)));
0056 return qMax(min, qMin(max, val));
0057 }
0058 template <typename T, typename U>
0059 constexpr inline QTypeTraits::Promoted<T, U> qBound(const U &min, const T &val, const T &max)
0060 {
0061 using P = QTypeTraits::Promoted<T, U>;
0062 Q_ASSERT(!(P(max) < P(min)));
0063 return qMax(min, qMin(max, val));
0064 }
0065
0066 QT_END_NAMESPACE
0067
0068 #endif