1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QMINMAX_H
5#define QMINMAX_H
6
7#if 0
8#pragma qt_class(QtMinMax)
9#pragma qt_sync_stop_processing
10#endif
11
12#include <QtCore/qassert.h>
13#include <QtCore/qtconfigmacros.h>
14#include <QtCore/qttypetraits.h>
15
16QT_BEGIN_NAMESPACE
17
18template <typename T>
19constexpr inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; }
20template <typename T>
21constexpr inline const T &qMax(const T &a, const T &b) { return (a < b) ? b : a; }
22template <typename T>
23constexpr inline const T &qBound(const T &min, const T &val, const T &max)
24{
25 Q_ASSERT(!(max < min));
26 return qMax(min, qMin(max, val));
27}
28template <typename T, typename U>
29constexpr inline QTypeTraits::Promoted<T, U> qMin(const T &a, const U &b)
30{
31 using P = QTypeTraits::Promoted<T, U>;
32 P _a = a;
33 P _b = b;
34 return (_a < _b) ? _a : _b;
35}
36template <typename T, typename U>
37constexpr inline QTypeTraits::Promoted<T, U> qMax(const T &a, const U &b)
38{
39 using P = QTypeTraits::Promoted<T, U>;
40 P _a = a;
41 P _b = b;
42 return (_a < _b) ? _b : _a;
43}
44template <typename T, typename U>
45constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const U &val, const T &max)
46{
47 Q_ASSERT(!(max < min));
48 return qMax(min, qMin(max, val));
49}
50template <typename T, typename U>
51constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const T &val, const U &max)
52{
53 using P = QTypeTraits::Promoted<T, U>;
54 Q_ASSERT(!(P(max) < P(min)));
55 return qMax(min, qMin(max, val));
56}
57template <typename T, typename U>
58constexpr inline QTypeTraits::Promoted<T, U> qBound(const U &min, const T &val, const T &max)
59{
60 using P = QTypeTraits::Promoted<T, U>;
61 Q_ASSERT(!(P(max) < P(min)));
62 return qMax(min, qMin(max, val));
63}
64
65QT_END_NAMESPACE
66
67#endif // QMINMAX_H
68

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtbase/src/corelib/global/qminmax.h