Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
q26numeric.h
Go to the documentation of this file.
1// Copyright (C) 2024 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// Qt-Security score:significant reason:default
4#ifndef Q26NUMERIC_H
5#define Q26NUMERIC_H
6
7#include <QtCore/qglobal.h>
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. Types and functions defined in this
14// file can reliably be replaced by their std counterparts, once available.
15// You may use these definitions in your own code, but be aware that we
16// will remove them once Qt depends on the C++ version that supports
17// them in namespace std. There will be NO deprecation warning, the
18// definitions will JUST go away.
19//
20// If you can't agree to these terms, don't use these definitions!
21//
22// We mean it.
23//
24
25#include <numeric>
26#include <limits>
27#include <type_traits>
28
29QT_BEGIN_NAMESPACE
30
31namespace q26 {
32
33// Like std::saturate_cast
34#ifdef __cpp_lib_saturation_arithmetic
35using std::saturate_cast;
36#else
37template <typename To, typename From>
38constexpr auto saturate_cast(From x)
39{
40 static_assert(std::is_integral_v<To>);
41 static_assert(std::is_integral_v<From>);
42
43 [[maybe_unused]]
44 constexpr auto Lo = (std::numeric_limits<To>::min)();
45 constexpr auto Hi = (std::numeric_limits<To>::max)();
46
47 if constexpr (std::is_signed_v<From> == std::is_signed_v<To>) {
48 // same signedness, we can accept regular integer conversion rules
49 return x < Lo ? Lo :
50 x > Hi ? Hi :
51 /*else*/ To(x);
52 } else {
53 if constexpr (std::is_signed_v<From>) { // ie. !is_signed_v<To>
54 if (x < From{0})
55 return To{0};
56 }
57
58 // from here on, x >= 0
59 using FromU = std::make_unsigned_t<From>;
60 using ToU = std::make_unsigned_t<To>;
61 return FromU(x) > ToU(Hi) ? Hi : To(x); // assumes Hi >= 0
62 }
63}
64#endif // __cpp_lib_saturation_arithmetic
65
66} // namespace q26
67
68QT_END_NAMESPACE
69
70#endif /* Q26NUMERIC_H */
Combined button and popup list for selecting options.
constexpr auto saturate_cast(From x)
Definition q26numeric.h:38
static HWND qt_create_internal_window(const QEventDispatcherWin32 *eventDispatcher)
static quint64 qt_msectime()
#define TIME_KILL_SYNCHRONOUS
#define WM_GESTURE
@ SendPostedEventsTimerId
#define WM_GESTURENOTIFY
#define DWORD_PTR
@ WM_QT_ACTIVATENOTIFIERS
@ WM_QT_SOCKETNOTIFIER
@ WM_QT_SENDPOSTEDEVENTS
#define WM_TOUCH
static bool isUserInputMessage(UINT message)
static ULONG calculateNextTimeout(WinTimerInfo *t, quint64 currentTime)
QHash< qintptr, QSockFd > QSFDict
QHash< int, WinTimerInfo * > WinTimerDict
QHash< qintptr, QSockNot * > QSNDict
QSockFd(long ev=0, long ma=0)
QSocketNotifier * obj
Qt::TimerType timerType