v8 10.2.154 (node 18.16.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
13namespace cppgc {
14
15class Visitor;
16
17namespace internal {
18template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
19 typename CheckingPolicy>
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>
130 static std::true_type SubclassCheck(
132 static std::false_type SubclassCheck(...);
133
134 public:
135 static constexpr bool value =
136 decltype(SubclassCheck(std::declval<BasicMemberCandidate*>()))::value;
137};
138
139template <typename T,
141 T, StrongMemberTag, DijkstraWriteBarrierPolicy>::value>
142struct IsMemberType : std::false_type {};
143
144template <typename T>
145struct IsMemberType<T, true> : std::true_type {};
146
147template <typename T, bool = IsSubclassOfBasicMemberTemplate<
148 T, WeakMemberTag, DijkstraWriteBarrierPolicy>::value>
149struct IsWeakMemberType : std::false_type {};
150
151template <typename T>
152struct IsWeakMemberType<T, true> : std::true_type {};
153
154template <typename T, bool = IsSubclassOfBasicMemberTemplate<
155 T, UntracedMemberTag, NoWriteBarrierPolicy>::value>
156struct IsUntracedMemberType : std::false_type {};
157
158template <typename T>
159struct IsUntracedMemberType<T, true> : std::true_type {};
160
161template <typename T>
163 private:
164 template <typename U, size_t = sizeof(U)>
165 static std::true_type IsSizeOfKnown(U*);
166 static std::false_type IsSizeOfKnown(...);
167
168 public:
169 static constexpr bool value =
170 decltype(IsSizeOfKnown(std::declval<T*>()))::value;
171};
172
173} // namespace internal
174
179template <typename T>
182
187template <typename T>
190
195template <typename T>
198
203template <typename T>
206
210template <typename T>
212
216template <typename T>
218
222template <typename T>
224
229template <typename T>
231
235template <typename T>
237
238} // namespace cppgc
239
240#endif // INCLUDE_CPPGC_TYPE_TRAITS_H_
constexpr bool IsTraceableV
Definition type-traits.h:58
constexpr bool IsGarbageCollectedTypeV
constexpr bool IsGarbageCollectedOrMixinTypeV
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