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