v8 12.4.254 (node 22.4.1)
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
13namespace cppgc {
14
15class Visitor;
16
17namespace internal {
18template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
19 typename CheckingPolicy, typename StorageType>
20class BasicMember;
21struct DijkstraWriteBarrierPolicy;
22struct NoWriteBarrierPolicy;
23class StrongMemberTag;
24class UntracedMemberTag;
25class WeakMemberTag;
26
27// Not supposed to be specialized by the user.
28template <typename T>
29struct IsWeak : std::false_type {};
30
31// IsTraceMethodConst is used to verify that all Trace methods are marked as
32// const. It is equivalent to IsTraceable but for a non-const object.
33template <typename T, typename = void>
34struct IsTraceMethodConst : std::false_type {};
35
36template <typename T>
37struct IsTraceMethodConst<T, std::void_t<decltype(std::declval<const T>().Trace(
38 std::declval<Visitor*>()))>> : std::true_type {
39};
40
41template <typename T, typename = void>
42struct IsTraceable : std::false_type {
43 static_assert(sizeof(T), "T must be fully defined");
44};
45
46template <typename T>
48 T, std::void_t<decltype(std::declval<T>().Trace(std::declval<Visitor*>()))>>
49 : std::true_type {
50 // All Trace methods should be marked as const. If an object of type
51 // 'T' is traceable then any object of type 'const T' should also
52 // be traceable.
53 static_assert(IsTraceMethodConst<T>(),
54 "Trace methods should be marked as const.");
55};
56
57template <typename T>
59
60template <typename T, typename = void>
61struct HasGarbageCollectedMixinTypeMarker : std::false_type {
62 static_assert(sizeof(T), "T must be fully defined");
63};
64
65template <typename T>
67 T, std::void_t<
68 typename std::remove_const_t<T>::IsGarbageCollectedMixinTypeMarker>>
69 : std::true_type {
70 static_assert(sizeof(T), "T must be fully defined");
71};
72
73template <typename T, typename = void>
74struct HasGarbageCollectedTypeMarker : std::false_type {
75 static_assert(sizeof(T), "T must be fully defined");
76};
77
78template <typename T>
80 T,
81 std::void_t<typename std::remove_const_t<T>::IsGarbageCollectedTypeMarker>>
82 : std::true_type {
83 static_assert(sizeof(T), "T must be fully defined");
84};
85
86template <typename T, bool = HasGarbageCollectedTypeMarker<T>::value,
88struct IsGarbageCollectedMixinType : std::false_type {
89 static_assert(sizeof(T), "T must be fully defined");
90};
91
92template <typename T>
93struct IsGarbageCollectedMixinType<T, false, true> : std::true_type {
94 static_assert(sizeof(T), "T must be fully defined");
95};
96
97template <typename T, bool = HasGarbageCollectedTypeMarker<T>::value>
98struct IsGarbageCollectedType : std::false_type {
99 static_assert(sizeof(T), "T must be fully defined");
100};
101
102template <typename T>
103struct IsGarbageCollectedType<T, true> : std::true_type {
104 static_assert(sizeof(T), "T must be fully defined");
105};
106
107template <typename T>
109 : std::integral_constant<bool, IsGarbageCollectedType<T>::value ||
110 IsGarbageCollectedMixinType<T>::value> {
111 static_assert(sizeof(T), "T must be fully defined");
112};
113
114template <typename T, bool = (HasGarbageCollectedTypeMarker<T>::value &&
115 HasGarbageCollectedMixinTypeMarker<T>::value)>
116struct IsGarbageCollectedWithMixinType : std::false_type {
117 static_assert(sizeof(T), "T must be fully defined");
118};
119
120template <typename T>
121struct IsGarbageCollectedWithMixinType<T, true> : std::true_type {
122 static_assert(sizeof(T), "T must be fully defined");
123};
124
125template <typename BasicMemberCandidate, typename WeaknessTag,
126 typename WriteBarrierPolicy>
128 private:
129 template <typename T, typename CheckingPolicy, typename StorageType>
130 static std::true_type SubclassCheck(
131 const BasicMember<T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy,
132 StorageType>*);
133 static std::false_type SubclassCheck(...);
134
135 public:
136 static constexpr bool value = decltype(SubclassCheck(
137 std::declval<std::decay_t<BasicMemberCandidate>*>()))::value;
138};
139
140template <typename T,
142 T, StrongMemberTag, DijkstraWriteBarrierPolicy>::value>
143struct IsMemberType : std::false_type {};
144
145template <typename T>
146struct IsMemberType<T, true> : std::true_type {};
147
148template <typename T, bool = IsSubclassOfBasicMemberTemplate<
149 T, WeakMemberTag, DijkstraWriteBarrierPolicy>::value>
150struct IsWeakMemberType : std::false_type {};
151
152template <typename T>
153struct IsWeakMemberType<T, true> : std::true_type {};
154
155template <typename T, bool = IsSubclassOfBasicMemberTemplate<
156 T, UntracedMemberTag, NoWriteBarrierPolicy>::value>
157struct IsUntracedMemberType : std::false_type {};
158
159template <typename T>
160struct IsUntracedMemberType<T, true> : std::true_type {};
161
162template <typename T>
164 private:
165 template <typename U, size_t = sizeof(U)>
166 static std::true_type IsSizeOfKnown(U*);
167 static std::false_type IsSizeOfKnown(...);
168
169 public:
170 static constexpr bool value =
171 decltype(IsSizeOfKnown(std::declval<T*>()))::value;
172};
173
174template <typename T, typename U>
175constexpr bool IsDecayedSameV =
176 std::is_same_v<std::decay_t<T>, std::decay_t<U>>;
177
178template <typename B, typename D>
179constexpr bool IsStrictlyBaseOfV =
180 std::is_base_of_v<std::decay_t<B>, std::decay_t<D>> &&
181 !IsDecayedSameV<B, D>;
182
183template <typename T>
184constexpr bool IsAnyMemberTypeV = false;
185
186template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
187 typename CheckingPolicy, typename StorageType>
189 T, WeaknessTag, WriteBarrierPolicy, CheckingPolicy, StorageType>> = true;
190
191} // namespace internal
192
197template <typename T>
200
205template <typename T>
208
213template <typename T>
216
221template <typename T>
224
228template <typename T>
230
234template <typename T>
236
240template <typename T>
242
247template <typename T>
249
253template <typename T>
255
259template <typename T>
261 IsMemberTypeV<T> || IsWeakMemberTypeV<T>;
262
266template <typename T>
267constexpr bool IsAnyMemberTypeV = internal::IsAnyMemberTypeV<std::decay_t<T>>;
268
269} // namespace cppgc
270
271#endif // INCLUDE_CPPGC_TYPE_TRAITS_H_
constexpr bool IsTraceableV
Definition type-traits.h:58
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