v8 14.1.146 (node 25.0.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
type-traits.h
Go to the documentation of this file.
1// Copyright 2020 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef INCLUDE_CPPGC_TYPE_TRAITS_H_
6#define INCLUDE_CPPGC_TYPE_TRAITS_H_
7
8// This file should stay with minimal dependencies to allow embedder to check
9// against Oilpan types without including any other parts.
10#include <cstddef>
11#include <type_traits>
12#include <utility>
13
14namespace cppgc {
15
16class Visitor;
17
18namespace internal {
19template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
20 typename CheckingPolicy, typename StorageType>
21class BasicMember;
24class StrongMemberTag;
25class UntracedMemberTag;
26class WeakMemberTag;
27
28// Not supposed to be specialized by the user.
29template <typename T>
30struct IsWeak : std::false_type {};
31
32// IsTraceMethodConst is used to verify that all Trace methods are marked as
33// const. It is equivalent to IsTraceable but for a non-const object.
34template <typename T, typename = void>
36
37template <typename T>
38struct IsTraceMethodConst<T, std::void_t<decltype(std::declval<const T>().Trace(
39 std::declval<Visitor*>()))>> : std::true_type {
40};
41
42template <typename T, typename = void>
44 static_assert(sizeof(T), "T must be fully defined");
45};
46
47template <typename T>
49 T, std::void_t<decltype(std::declval<T>().Trace(std::declval<Visitor*>()))>>
50 : std::true_type {
51 // All Trace methods should be marked as const. If an object of type
52 // 'T' is traceable then any object of type 'const T' should also
53 // be traceable.
54 static_assert(IsTraceMethodConst<T>(),
55 "Trace methods should be marked as const.");
56};
57
58template <typename T>
59constexpr bool IsTraceableV = IsTraceable<T>::value;
60
61template <typename T, typename = void>
63 static_assert(sizeof(T), "T must be fully defined");
64};
65
66template <typename T>
68 T, std::void_t<
70 : std::true_type {
71 static_assert(sizeof(T), "T must be fully defined");
72};
73
74template <typename T, typename = void>
76 static_assert(sizeof(T), "T must be fully defined");
77};
78
79template <typename T>
81 T,
83 : std::true_type {
84 static_assert(sizeof(T), "T must be fully defined");
85};
86
87template <typename T, bool = HasGarbageCollectedTypeMarker<T>::value,
90 static_assert(sizeof(T), "T must be fully defined");
91};
92
93template <typename T>
94struct IsGarbageCollectedMixinType<T, false, true> : std::true_type {
95 static_assert(sizeof(T), "T must be fully defined");
96};
97
98template <typename T, bool = HasGarbageCollectedTypeMarker<T>::value>
100 static_assert(sizeof(T), "T must be fully defined");
101};
102
103template <typename T>
105 static_assert(sizeof(T), "T must be fully defined");
106};
107
108template <typename T>
112 static_assert(sizeof(T), "T must be fully defined");
113};
114
115template <typename T, bool = (HasGarbageCollectedTypeMarker<T>::value &&
118 static_assert(sizeof(T), "T must be fully defined");
119};
120
121template <typename T>
123 static_assert(sizeof(T), "T must be fully defined");
124};
125
126template <typename BasicMemberCandidate, typename WeaknessTag,
127 typename WriteBarrierPolicy>
129 private:
130 template <typename T, typename CheckingPolicy, typename StorageType>
131 static std::true_type SubclassCheck(
132 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
133 StorageType>*);
134 static std::false_type SubclassCheck(...);
135
136 public:
137 static constexpr bool value = decltype(SubclassCheck(
139};
140
141template <typename T,
143 T, StrongMemberTag, DijkstraWriteBarrierPolicy>::value>
145
146template <typename T>
147struct IsMemberType<T, true> : std::true_type {};
148
149template <typename T, bool = IsSubclassOfBasicMemberTemplate<
150 T, WeakMemberTag, DijkstraWriteBarrierPolicy>::value>
152
153template <typename T>
154struct IsWeakMemberType<T, true> : std::true_type {};
155
156template <typename T, bool = IsSubclassOfBasicMemberTemplate<
157 T, UntracedMemberTag, NoWriteBarrierPolicy>::value>
159
160template <typename T>
161struct IsUntracedMemberType<T, true> : std::true_type {};
162
163template <typename T>
165 private:
166 template <typename U, size_t = sizeof(U)>
167 static std::true_type IsSizeOfKnown(U*);
168 static std::false_type IsSizeOfKnown(...);
169
170 public:
171 static constexpr bool value =
172 decltype(IsSizeOfKnown(std::declval<T*>()))::value;
173};
174
175template <typename T, typename U>
176constexpr bool IsDecayedSameV =
178
179template <typename B, typename D>
180constexpr bool IsStrictlyBaseOfV =
182 !IsDecayedSameV<B, D>;
183
184template <typename T>
185constexpr bool IsAnyMemberTypeV = false;
186
187template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
188 typename CheckingPolicy, typename StorageType>
189constexpr bool IsAnyMemberTypeV<internal::BasicMember<
190 T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy, StorageType>> = true;
191
192} // namespace internal
193
194/**
195 * Value is true for types that inherit from `GarbageCollectedMixin` but not
196 * `GarbageCollected<T>` (i.e., they are free mixins), and false otherwise.
197 */
198template <typename T>
201
202/**
203 * Value is true for types that inherit from `GarbageCollected<T>`, and false
204 * otherwise.
205 */
206template <typename T>
209
210/**
211 * Value is true for types that inherit from either `GarbageCollected<T>` or
212 * `GarbageCollectedMixin`, and false otherwise.
213 */
214template <typename T>
217
218/**
219 * Value is true for types that inherit from `GarbageCollected<T>` and
220 * `GarbageCollectedMixin`, and false otherwise.
221 */
222template <typename T>
225
226/**
227 * Value is true for types of type `Member<T>`, and false otherwise.
228 */
229template <typename T>
231
232/**
233 * Value is true for types of type `UntracedMember<T>`, and false otherwise.
234 */
235template <typename T>
237
238/**
239 * Value is true for types of type `WeakMember<T>`, and false otherwise.
240 */
241template <typename T>
243
244/**
245 * Value is true for types that are considered weak references, and false
246 * otherwise.
247 */
248template <typename T>
249constexpr bool IsWeakV = internal::IsWeak<T>::value;
250
251/**
252 * Value is true for types that are complete, and false otherwise.
253 */
254template <typename T>
256
257/**
258 * Value is true for member types `Member<T>` and `WeakMember<T>`.
259 */
260template <typename T>
263
264/**
265 * Value is true for any member type.
266 */
267template <typename T>
269
270} // namespace cppgc
271
272#endif // INCLUDE_CPPGC_TYPE_TRAITS_H_
constexpr bool IsTraceableV
Definition type-traits.h:59
constexpr bool IsAnyMemberTypeV
constexpr bool IsDecayedSameV
constexpr bool IsStrictlyBaseOfV
constexpr bool IsAnyMemberTypeV
constexpr bool IsGarbageCollectedTypeV
constexpr bool IsGarbageCollectedOrMixinTypeV
constexpr bool IsMemberOrWeakMemberTypeV
constexpr bool IsWeakMemberTypeV
constexpr bool IsCompleteV
constexpr bool IsGarbageCollectedMixinTypeV
constexpr bool IsWeakV
constexpr bool IsGarbageCollectedWithMixinTypeV
constexpr bool IsUntracedMemberTypeV
constexpr bool IsMemberTypeV
static constexpr bool value