5 #ifndef INCLUDE_CPPGC_INTERNAL_FINALIZER_TRAIT_H_
6 #define INCLUDE_CPPGC_INTERNAL_FINALIZER_TRAIT_H_
10 #include "cppgc/type-traits.h"
15 using FinalizationCallback =
void (*)(
void*);
17 template <
typename T,
typename =
void>
22 T, void_t<
decltype(std::declval<T>().FinalizeGarbageCollectedObject())>>
26 template <
typename T,
bool isFinalized>
27 struct FinalizerTraitImpl;
30 struct FinalizerTraitImpl<T,
true> {
34 static void Call(
void* obj) {
35 static_cast<T*>(obj)->FinalizeGarbageCollectedObject();
41 static void Call(
void* obj) {
static_cast<T*>(obj)->~T(); }
50 static_assert(
sizeof(T),
"T must be fully defined");
51 FinalizeImpl::Call(obj);
56 struct FinalizerTraitImpl<T,
false> {
58 static_assert(
sizeof(T),
"T must be fully defined");
70 static constexpr bool kNonTrivialFinalizer =
72 !std::is_trivially_destructible<
typename std::remove_cv<T>::type>::value;
74 static void Finalize(
void* obj) {
75 internal::FinalizerTraitImpl<T, kNonTrivialFinalizer>::Finalize(obj);
79 static constexpr bool HasFinalizer() {
return kNonTrivialFinalizer; }
83 kNonTrivialFinalizer ? Finalize :
nullptr;