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 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | namespace q20 { |
31 | // like std::is_constant_evaluated |
32 | #ifdef __cpp_lib_is_constant_evaluated |
33 | using std::is_constant_evaluated; |
34 | #define QT_SUPPORTS_IS_CONSTANT_EVALUATED |
35 | #else |
36 | constexpr bool is_constant_evaluated() noexcept |
37 | { |
38 | #ifdef Q_OS_INTEGRITY |
39 | // Integrity complains "calling __has_builtin() from a constant expression". |
40 | // Avoid the __has_builtin check until we know what's going on. |
41 | return false; |
42 | #elif __has_builtin(__builtin_is_constant_evaluated) || \ |
43 | (defined(Q_CC_MSVC_ONLY) /* >= 1925, but we require 1927 in qglobal.h */) |
44 | # define QT_SUPPORTS_IS_CONSTANT_EVALUATED |
45 | return __builtin_is_constant_evaluated(); |
46 | #else |
47 | return false; |
48 | #endif |
49 | } |
50 | #endif // __cpp_lib_is_constant_evaluated |
51 | } |
52 | |
53 | namespace q20 { |
54 | // like std::remove_cvref(_t) |
55 | #ifdef __cpp_lib_remove_cvref |
56 | using std::remove_cvref; |
57 | using std::remove_cvref_t; |
58 | #else |
59 | template <typename T> |
60 | using remove_cvref = std::remove_cv<std::remove_reference_t<T>>; |
61 | template <typename T> |
62 | using remove_cvref_t = std::remove_cv_t<std::remove_reference_t<T>>; |
63 | #endif // __cpp_lib_remove_cvref |
64 | } |
65 | |
66 | namespace q20 { |
67 | // like std::type_identity(_t) |
68 | #ifdef __cpp_lib_type_identity |
69 | using std::type_identity; |
70 | using std::type_identity_t; |
71 | #else |
72 | template <typename T> |
73 | struct type_identity { using type = T; }; |
74 | template <typename T> |
75 | using type_identity_t = typename type_identity<T>::type; |
76 | #endif // __cpp_lib_type_identity |
77 | } |
78 | |
79 | QT_END_NAMESPACE |
80 | |
81 | #endif /* Q20TYPE_TRAITS_H */ |
82 | |