chromium/v8/include/cppgc/type-traits.h

// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef INCLUDE_CPPGC_TYPE_TRAITS_H_
#define INCLUDE_CPPGC_TYPE_TRAITS_H_

// This file should stay with minimal dependencies to allow embedder to check
// against Oilpan types without including any other parts.
#include <cstddef>
#include <type_traits>

namespace cppgc {

class Visitor;

namespace internal {
template <typename T, typename WeaknessTag, typename WriteBarrierPolicy,
          typename CheckingPolicy, typename StorageType>
class BasicMember;
struct DijkstraWriteBarrierPolicy;
struct NoWriteBarrierPolicy;
class StrongMemberTag;
class UntracedMemberTag;
class WeakMemberTag;

// Not supposed to be specialized by the user.
template <typename T>
struct IsWeak : std::false_type {};

// IsTraceMethodConst is used to verify that all Trace methods are marked as
// const. It is equivalent to IsTraceable but for a non-const object.
template <typename T, typename = void>
struct IsTraceMethodConst : std::false_type {};

IsTraceMethodConst<T, std::void_t<decltype(std::declval<const T>().Trace(std::declval<Visitor *>()))>>;

template <typename T, typename = void>
struct IsTraceable : std::false_type {};

IsTraceable<T, std::void_t<decltype(std::declval<T>().Trace(std::declval<Visitor *>()))>>;

IsTraceableV;

template <typename T, typename = void>
struct HasGarbageCollectedMixinTypeMarker : std::false_type {};

HasGarbageCollectedMixinTypeMarker<T, std::void_t<typename std::remove_const_t<T>::IsGarbageCollectedMixinTypeMarker>>;

template <typename T, typename = void>
struct HasGarbageCollectedTypeMarker : std::false_type {};

HasGarbageCollectedTypeMarker<T, std::void_t<typename std::remove_const_t<T>::IsGarbageCollectedTypeMarker>>;

template <typename T, bool = HasGarbageCollectedTypeMarker<T>::value,
          bool = HasGarbageCollectedMixinTypeMarker<T>::value>
struct IsGarbageCollectedMixinType : std::false_type {};

IsGarbageCollectedMixinType<T, false, true>;

template <typename T, bool = HasGarbageCollectedTypeMarker<T>::value>
struct IsGarbageCollectedType : std::false_type {};

IsGarbageCollectedType<T, true>;

template <typename T>
struct IsGarbageCollectedOrMixinType
    : std::integral_constant<bool, IsGarbageCollectedType<T>::value ||
                                       IsGarbageCollectedMixinType<T>::value> {};

template <typename T, bool = (HasGarbageCollectedTypeMarker<T>::value &&
                              HasGarbageCollectedMixinTypeMarker<T>::value)>
struct IsGarbageCollectedWithMixinType : std::false_type {};

IsGarbageCollectedWithMixinType<T, true>;

template <typename BasicMemberCandidate, typename WeaknessTag,
          typename WriteBarrierPolicy>
struct IsSubclassOfBasicMemberTemplate {};

template <typename T,
          bool = IsSubclassOfBasicMemberTemplate<
              T, StrongMemberTag, DijkstraWriteBarrierPolicy>::value>
struct IsMemberType : std::false_type {};

IsMemberType<T, true>;

template <typename T, bool = IsSubclassOfBasicMemberTemplate<
                          T, WeakMemberTag, DijkstraWriteBarrierPolicy>::value>
struct IsWeakMemberType : std::false_type {};

IsWeakMemberType<T, true>;

template <typename T, bool = IsSubclassOfBasicMemberTemplate<
                          T, UntracedMemberTag, NoWriteBarrierPolicy>::value>
struct IsUntracedMemberType : std::false_type {};

IsUntracedMemberType<T, true>;

template <typename T>
struct IsComplete {};

IsDecayedSameV;

IsStrictlyBaseOfV;

IsAnyMemberTypeV;

IsAnyMemberTypeV;

}  // namespace internal

/**
 * Value is true for types that inherit from `GarbageCollectedMixin` but not
 * `GarbageCollected<T>` (i.e., they are free mixins), and false otherwise.
 */
IsGarbageCollectedMixinTypeV;

/**
 * Value is true for types that inherit from `GarbageCollected<T>`, and false
 * otherwise.
 */
IsGarbageCollectedTypeV;

/**
 * Value is true for types that inherit from either `GarbageCollected<T>` or
 * `GarbageCollectedMixin`, and false otherwise.
 */
IsGarbageCollectedOrMixinTypeV;

/**
 * Value is true for types that inherit from `GarbageCollected<T>` and
 * `GarbageCollectedMixin`, and false otherwise.
 */
IsGarbageCollectedWithMixinTypeV;

/**
 * Value is true for types of type `Member<T>`, and false otherwise.
 */
IsMemberTypeV;

/**
 * Value is true for types of type `UntracedMember<T>`, and false otherwise.
 */
IsUntracedMemberTypeV;

/**
 * Value is true for types of type `WeakMember<T>`, and false otherwise.
 */
IsWeakMemberTypeV;

/**
 * Value is true for types that are considered weak references, and false
 * otherwise.
 */
IsWeakV;

/**
 * Value is true for types that are complete, and false otherwise.
 */
IsCompleteV;

/**
 * Value is true for member types `Member<T>` and `WeakMember<T>`.
 */
IsMemberOrWeakMemberTypeV;

/**
 * Value is true for any member type.
 */
IsAnyMemberTypeV;

}  // namespace cppgc

#endif  // INCLUDE_CPPGC_TYPE_TRAITS_H_