swift
Loading...
Searching...
No Matches
typetraits.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_MISC_TYPETRAITS_H
7#define SWIFT_MISC_TYPETRAITS_H
8
9#include <type_traits>
10#include <utility> // for std::swap
11
12class QDBusArgument;
13
14namespace swift::misc
15{
16
18
19 namespace private_ns
20 {
22 template <typename T, bool = std::is_class_v<T>>
23 struct SyntheticDerived : public T
24 {};
26 template <typename T>
27 struct SyntheticDerived<T, false>
28 {};
30 } // namespace private_ns
31
35 enum class ParameterPassBy
36 {
37 Value,
38 ConstRef
39 };
40
44 template <typename T>
46 {
48 static constexpr ParameterPassBy passBy =
49 (sizeof(T) <= 16 && std::is_trivially_copy_constructible_v<T> && std::is_trivially_destructible_v<T>) ?
50 ParameterPassBy::Value :
51 ParameterPassBy::ConstRef;
52 };
53
57 template <typename T, typename = std::void_t<>>
58 struct THasToQString : public std::false_type
59 {};
60
61 template <typename T>
62 struct THasToQString<T, std::void_t<decltype(std::declval<T>().toQString())>> : public std::true_type
63 {};
65
69 template <typename T, typename = std::void_t<>>
70 struct THasPushBack : public std::false_type
71 {};
72
73 template <typename T>
74 struct THasPushBack<T, std::void_t<decltype(std::declval<T>().push_back(std::declval<typename T::value_type>()))>> :
75 public std::true_type
76 {};
78
82 template <typename T, typename = std::void_t<>>
83 struct THasGetLogCategories : public std::false_type
84 {};
85
86 template <typename T>
87 struct THasGetLogCategories<T, std::void_t<decltype(T::getLogCategories())>> : public std::true_type
88 {};
90
94 template <typename T, typename = std::void_t<>>
95 struct TModelsQHashKey : public std::false_type
96 {};
97
98 template <typename T>
99 struct TModelsQHashKey<T, std::void_t<decltype(std::declval<T>() == std::declval<T>(), qHash(std::declval<T>()))>> :
100 public std::true_type
101 {};
103
107 template <typename T, typename = std::void_t<>>
108 struct TModelsQMapKey : public std::false_type
109 {};
110
111 template <typename T>
112 struct TModelsQMapKey<T, std::void_t<decltype(std::declval<T>() < std::declval<T>())>> : public std::true_type
113 {};
115
119 template <typename T, typename U, typename = std::void_t<>>
120 struct THasCompare : public std::false_type
121 {};
122
123 template <typename T, typename U>
124 struct THasCompare<T, U, std::void_t<decltype(compare(std::declval<T>(), std::declval<U>()))>> :
125 public std::true_type
126 {};
128
133 template <typename T, typename = std::void_t<>>
134 struct THasComparePropertyByIndex : public std::false_type
135 {};
136
137 template <typename T>
138 struct THasComparePropertyByIndex<T, std::void_t<decltype(std::declval<T>().comparePropertyByIndex(
139 std::declval<CPropertyIndexRef>(), std::declval<const T &>()))>> :
140 public std::true_type
141 {};
143
148 template <typename T, typename = std::void_t<>>
149 struct THasPropertyByIndex : public std::false_type
150 {};
151
152 template <typename T>
153 struct THasPropertyByIndex<
154 T, std::void_t<decltype(std::declval<T>().propertyByIndex(std::declval<CPropertyIndexRef>()))>> :
155 public std::true_type
156 {};
158
162 template <typename T, typename U, typename = std::void_t<>>
163 struct TIsEqualityComparable : public std::false_type
164 {};
165
166 template <typename T, typename U>
167 struct TIsEqualityComparable<T, U, std::void_t<decltype(std::declval<T>() == std::declval<U>())>> :
168 public std::true_type
169 {};
171
175 template <typename T, typename = std::void_t<>>
176 struct THasMarshallMethods : public std::false_type
177 {};
178
179 template <typename T>
180 struct THasMarshallMethods<
181 T, std::void_t<decltype(std::declval<const T &>().marshallToDbus(std::declval<QDBusArgument &>()),
182 std::declval<T &>().unmarshallFromDbus(std::declval<const QDBusArgument &>()))>> :
183 public std::true_type
184 {};
186
190 template <typename T, typename = std::void_t<>>
191 struct TIsQPrivateSignal : public std::false_type
192 {};
193
194 template <typename T>
195 struct TIsQPrivateSignal<T, std::void_t<typename private_ns::SyntheticDerived<T>::QPrivateSignal>> :
196 public std::is_same<T, typename private_ns::SyntheticDerived<T>::QPrivateSignal>
197 {};
199
200} // namespace swift::misc
201
202#endif // SWIFT_MISC_TYPETRAITS_H
Non-owning reference to a CPropertyIndex with a subset of its features.
Free functions in swift::misc.
ParameterPassBy
Whether an input parameter type should be passed by value or by const reference.
Definition typetraits.h:36
Trait which is true if the expression compare(a, b) is valid when a and b are instances of T and U.
Definition typetraits.h:121
Trait which is true if the expression a.compareByPropertyIndex(b, i) is valid when a and b are instan...
Definition typetraits.h:135
Trait to detect whether a class T has a static member function named getLogCategories.
Definition typetraits.h:84
Trait which is true if T has methods marshallToDbus and unmarshallFromDbus.
Definition typetraits.h:177
Trait which is true if the expression a.propertyByIndex(i) is valid with a is an instance of T and i ...
Definition typetraits.h:150
Trait which is true if the expression a.push_back(v) is valid when a and v are instances of T and T::...
Definition typetraits.h:71
Trait to detect whether T contains a member function toQString.
Definition typetraits.h:59
Trait which is true if the expression a == b is valid when a and b are instances of T and U.
Definition typetraits.h:164
Trait that detects if a type is QPrivateSignal.
Definition typetraits.h:192
Trait to detect whether a class T can be used as a key in a QHash.
Definition typetraits.h:96
Trait to detect whether a class T can be used as a key in a QMap.
Definition typetraits.h:109
Trait to detect properties of function parameter types.
Definition typetraits.h:46
static constexpr ParameterPassBy passBy
Whether the input parameter type T should be passed by value or by const reference.
Definition typetraits.h:48