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
qxptype_traits.h
Go to the documentation of this file.
1// Copyright (C) 2023 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>, Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2// Copyright (C) 2022 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QXPTYPE_TRAITS_H
7#define QXPTYPE_TRAITS_H
8
9#include <QtCore/qtconfigmacros.h>
10#include <QtCore/qcompilerdetection.h>
11
12#include <QtCore/q23type_traits.h>
13
14//
15// W A R N I N G
16// -------------
17//
18// This file is not part of the Qt API. Types and functions defined in this
19// file can reliably be replaced by their std counterparts, once available.
20// You may use these definitions in your own code, but be aware that we
21// will remove them once Qt depends on the C++ version that supports
22// them in namespace std. There will be NO deprecation warning, the
23// definitions will JUST go away.
24//
25// If you can't agree to these terms, don't use these definitions!
26//
27// We mean it.
28//
29
30QT_BEGIN_NAMESPACE
31
32// like std::experimental::{nonesuch,is_detected/_v}(LFTSv2)
33namespace qxp {
34
35struct nonesuch {
36 ~nonesuch() = delete;
37 nonesuch(const nonesuch&) = delete;
38 void operator=(const nonesuch&) = delete;
39};
40
41namespace _detail {
42 template <typename T, typename Void, template <typename...> class Op, typename...Args>
43 struct detector {
45 using type = T;
46 };
47 template <typename T, template <typename...> class Op, typename...Args>
48 struct detector<T, std::void_t<Op<Args...>>, Op, Args...> {
50 using type = Op<Args...>;
51 };
52} // namespace _detail
53
54template <template <typename...> class Op, typename...Args>
55using is_detected = typename _detail::detector<qxp::nonesuch, void, Op, Args...>::value_t;
56
57template <template <typename...> class Op, typename...Args>
58constexpr inline bool is_detected_v = qxp::is_detected<Op, Args...>::value;
59
60template <typename Default, template <typename...> class Op, typename...Args>
62
63template <typename Default, template <typename...> class Op, typename...Args>
64using detected_or_t = typename qxp::detected_or<Default, Op, Args...>::type;
65
66template <template <typename...> class Op, typename...Args>
68
69// qxp::is_virtual_base_of_v<B, D> is true if and only if B is a virtual base class of D.
70// Just like is_base_of:
71// * only works on complete types;
72// * B and D must be class types;
73// * ignores cv-qualifications;
74// * B may be inaccessibile.
75
76#ifdef __cpp_lib_is_virtual_base_of
79#else
80namespace _detail {
81 // Check that From* can be converted to To*, ignoring accessibility.
82 // This can be done using a C cast (see [expr.cast]/4).
83QT_WARNING_PUSH
84QT_WARNING_DISABLE_GCC("-Wold-style-cast")
85QT_WARNING_DISABLE_CLANG("-Wold-style-cast")
86 template <typename From, typename To>
88 (To *)std::declval<From *>()
89 );
91
92 template <typename Base, typename Derived, typename = void>
94
95 template <typename Base, typename Derived>
100 // Base is a base class of Derived.
102
103 // Check that Derived* can be converted to Base*, ignoring
104 // accessibility. If this is possible, then Base is
105 // an unambiguous base of Derived (=> virtual bases are always
106 // unambiguous).
108
109 // Check that Base* can _not_ be converted to Derived*,
110 // again ignoring accessibility. This seals the deal:
111 // if this conversion cannot happen, it means that Base is an
112 // ambiguous base and/or it is a virtual base.
113 // But we have already established that Base is an unambiguous
114 // base, hence: Base is a virtual base.
115 std::negation<
117 >
118 >
119 >
120 > : std::true_type {};
121}
122
123template <typename Base, typename Derived>
125
126template <typename Base, typename Derived>
128#endif // __cpp_lib_is_virtual_base_of
129
130} // namespace qxp
131
132QT_END_NAMESPACE
133
134#endif // QXPTYPE_TRAITS_H
_detail::is_virtual_base_of< std::remove_cv_t< Base >, std::remove_cv_t< Derived > > is_virtual_base_of
constexpr bool is_virtual_base_of_v
constexpr bool is_detected_v
nonesuch(const nonesuch &)=delete
void operator=(const nonesuch &)=delete
~nonesuch()=delete