Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qminmax.h
Go to the documentation of this file.
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
15#include <type_traits>
16
18
19namespace QTypeTraits {
20
21namespace detail {
22template<typename T, typename U,
23 typename = std::enable_if_t<std::is_arithmetic_v<T> && std::is_arithmetic_v<U> &&
24 std::is_floating_point_v<T> == std::is_floating_point_v<U> &&
25 std::is_signed_v<T> == std::is_signed_v<U> &&
26 !std::is_same_v<T, bool> && !std::is_same_v<U, bool> &&
27 !std::is_same_v<T, char> && !std::is_same_v<U, char>>>
29{
30 using type = decltype(T() + U());
31};
32}
33
34template <typename T, typename U>
36
37}
38
39template <typename T>
40constexpr inline const T &qMin(const T &a, const T &b) { return (a < b) ? a : b; }
41template <typename T>
42constexpr inline const T &qMax(const T &a, const T &b) { return (a < b) ? b : a; }
43template <typename T>
44constexpr inline const T &qBound(const T &min, const T &val, const T &max)
45{
46 Q_ASSERT(!(max < min));
47 return qMax(min, qMin(max, val));
48}
49template <typename T, typename U>
50constexpr inline QTypeTraits::Promoted<T, U> qMin(const T &a, const U &b)
51{
53 P _a = a;
54 P _b = b;
55 return (_a < _b) ? _a : _b;
56}
57template <typename T, typename U>
58constexpr inline QTypeTraits::Promoted<T, U> qMax(const T &a, const U &b)
59{
61 P _a = a;
62 P _b = b;
63 return (_a < _b) ? _b : _a;
64}
65template <typename T, typename U>
66constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const U &val, const T &max)
67{
68 Q_ASSERT(!(max < min));
69 return qMax(min, qMin(max, val));
70}
71template <typename T, typename U>
72constexpr inline QTypeTraits::Promoted<T, U> qBound(const T &min, const T &val, const U &max)
73{
75 Q_ASSERT(!(P(max) < P(min)));
76 return qMax(min, qMin(max, val));
77}
78template <typename T, typename U>
79constexpr inline QTypeTraits::Promoted<T, U> qBound(const U &min, const T &val, const T &max)
80{
82 Q_ASSERT(!(P(max) < P(min)));
83 return qMax(min, qMin(max, val));
84}
85
87
88#endif // QMINMAX_H
Combined button and popup list for selecting options.
typename detail::Promoted< T, U >::type Promoted
Definition qminmax.h:35
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint GLfloat * val
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
decltype(T()+U()) type
Definition qminmax.h:30