Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qttypetraits.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 QTTYPETRAITS_H
5#define QTTYPETRAITS_H
6
7#include <QtCore/qtconfigmacros.h>
8#include <QtCore/qtdeprecationmarkers.h>
9
10#include <type_traits>
11#include <utility>
12
13#if 0
14#pragma qt_class(QtTypeTraits)
15#pragma qt_sync_stop_processing
16#endif
17
19
20// like std::is_constant_evaluated
21#define QT_SUPPORTS_IS_CONSTANT_EVALUATED
22#ifdef __cpp_lib_is_constant_evaluated
23constexpr bool qIsConstantEvaluated() noexcept
24{
25 return std::is_constant_evaluated();
26}
27#elif __has_builtin(__builtin_is_constant_evaluated) || \
28 (defined(Q_CC_MSVC_ONLY) /* >= 1925, but we require 1927 in qglobal.h */)
29constexpr bool qIsConstantEvaluated() noexcept
30{
31 return __builtin_is_constant_evaluated();
32}
33#else
34# undef QT_SUPPORTS_IS_CONSTANT_EVALUATED
35#endif
36
37// like std::to_underlying
38template <typename Enum>
39constexpr std::underlying_type_t<Enum> qToUnderlying(Enum e) noexcept
40{
41 return static_cast<std::underlying_type_t<Enum>>(e);
42}
43
44#ifndef QT_NO_AS_CONST
45#if QT_DEPRECATED_SINCE(6, 6)
46
47// this adds const to non-const objects (like std::as_const)
48template <typename T>
49QT_DEPRECATED_VERSION_X_6_6("Use std::as_const() instead.")
50constexpr typename std::add_const<T>::type &qAsConst(T &t) noexcept { return t; }
51// prevent rvalue arguments:
52template <typename T>
53void qAsConst(const T &&) = delete;
54
55#endif // QT_DEPRECATED_SINCE(6, 6)
56#endif // QT_NO_AS_CONST
57
58#ifndef QT_NO_QEXCHANGE
59
60// like std::exchange
61template <typename T, typename U = T>
62constexpr T qExchange(T &t, U &&newValue)
63noexcept(std::conjunction_v<std::is_nothrow_move_constructible<T>,
64 std::is_nothrow_assignable<T &, U>>)
65{
66 T old = std::move(t);
67 t = std::forward<U>(newValue);
68 return old;
69}
70
71#endif // QT_NO_QEXCHANGE
72
73namespace QtPrivate {
74// helper to be used to trigger a "dependent static_assert(false)"
75// (for instance, in a final `else` branch of a `if constexpr`.)
76template <typename T> struct type_dependent_false : std::false_type {};
77template <auto T> struct value_dependent_false : std::false_type {};
78}
79
81
82#endif // QTTYPETRAITS_H
double e
Combined button and popup list for selecting options.
\macro QT_NAMESPACE
GLenum type
GLdouble GLdouble t
Definition qopenglext.h:243
#define QT_DEPRECATED_VERSION_X_6_6(text)
constexpr std::underlying_type_t< Enum > qToUnderlying(Enum e) noexcept
constexpr T qExchange(T &t, U &&newValue) noexcept(std::conjunction_v< std::is_nothrow_move_constructible< T >, std::is_nothrow_assignable< T &, U > >)