Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:09:25

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