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
q20type_traits.h
Go to the documentation of this file.
1// Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
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 Q20TYPE_TRAITS_H
5#define Q20TYPE_TRAITS_H
6
7#include <QtCore/qcompilerdetection.h>
8#include <QtCore/qsystemdetection.h>
9#include <QtCore/qtconfigmacros.h>
10
11//
12// W A R N I N G
13// -------------
14//
15// This file is not part of the Qt API. Types and functions defined in this
16// file can reliably be replaced by their std counterparts, once available.
17// You may use these definitions in your own code, but be aware that we
18// will remove them once Qt depends on the C++ version that supports
19// them in namespace std. There will be NO deprecation warning, the
20// definitions will JUST go away.
21//
22// If you can't agree to these terms, don't use these definitions!
23//
24// We mean it.
25//
26
27#include <type_traits>
28
30
31namespace q20 {
32// like std::is_(un)bounded_array
33#ifdef __cpp_lib_bounded_array_traits
38#else
39template <typename T> struct is_bounded_array : std::false_type {};
40template <typename T, std::size_t N> struct is_bounded_array<T[N]> : std::true_type {};
41template <typename T> struct is_unbounded_array : std::false_type {};
42template <typename T> struct is_unbounded_array<T[]> : std::true_type {};
43template <typename T> constexpr inline bool is_bounded_array_v = q20::is_bounded_array<T>::value;
44template <typename T> constexpr inline bool is_unbounded_array_v = q20::is_unbounded_array<T>::value;
45#endif
46}
47
48namespace q20 {
49// like std::is_constant_evaluated
50#ifdef __cpp_lib_is_constant_evaluated
52#define QT_SUPPORTS_IS_CONSTANT_EVALUATED
53#else
54constexpr bool is_constant_evaluated() noexcept
55{
56#ifdef Q_OS_INTEGRITY
57 // Integrity complains "calling __has_builtin() from a constant expression".
58 // Avoid the __has_builtin check until we know what's going on.
59 return false;
60#elif __has_builtin(__builtin_is_constant_evaluated) ||
61 (defined(Q_CC_MSVC_ONLY) /* >= 1925, but we require 1927 in qglobal.h */)
62# define QT_SUPPORTS_IS_CONSTANT_EVALUATED
63 return __builtin_is_constant_evaluated();
64#else
65 return false;
66#endif
67}
68#endif // __cpp_lib_is_constant_evaluated
69}
70
71namespace q20 {
72// like std::remove_cvref(_t)
73#ifdef __cpp_lib_remove_cvref
74using std::remove_cvref;
75using std::remove_cvref_t;
76#else
77template <typename T>
79template <typename T>
81#endif // __cpp_lib_remove_cvref
82}
83
84namespace q20 {
85// like std::type_identity(_t)
86#ifdef __cpp_lib_type_identity
87using std::type_identity;
88using std::type_identity_t;
89#else
90template <typename T>
91struct type_identity { using type = T; };
92template <typename T>
93using type_identity_t = typename type_identity<T>::type;
94#endif // __cpp_lib_type_identity
95}
96
97QT_END_NAMESPACE
98
99#endif /* Q20TYPE_TRAITS_H */
Combined button and popup list for selecting options.
constexpr bool is_constant_evaluated() noexcept
constexpr bool is_bounded_array_v
typename type_identity< T >::type type_identity_t
constexpr bool is_unbounded_array_v
#define __has_builtin(x)