chromium/third_party/blink/renderer/platform/wtf/type_traits.h

/*
 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
 * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TYPE_TRAITS_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TYPE_TRAITS_H_

#include <cstddef>
#include <type_traits>
#include <utility>
#include "base/compiler_specific.h"
#include "build/build_config.h"
#include "v8/include/cppgc/type-traits.h"  // nogncheck

namespace WTF {

// Returns a string that contains the type name of |T| as a substring.
template <typename T>
inline const char* GetStringWithTypeName() {}

template <typename T, typename U>
struct IsSubclass {};

template <typename T, template <typename... V> class U>
struct IsSubclassOfTemplate {};

template <typename T, template <typename V, size_t W> class U>
struct IsSubclassOfTemplateTypenameSize {};

template <typename T, template <typename V, size_t W, typename X> class U>
struct IsSubclassOfTemplateTypenameSizeTypename {};

template <typename T>
struct IsTraceable : cppgc::internal::IsTraceable<T> {};

template <typename T>
struct IsGarbageCollectedType
    : cppgc::internal::IsGarbageCollectedOrMixinType<T> {};

template <typename T>
struct IsWeak : cppgc::internal::IsWeak<T> {};

template <typename T>
struct IsMemberType : std::bool_constant<cppgc::IsMemberTypeV<T>> {};

template <typename T>
struct IsWeakMemberType : std::bool_constant<cppgc::IsWeakMemberTypeV<T>> {};

template <typename T>
struct IsMemberOrWeakMemberType
    : std::bool_constant<cppgc::IsMemberTypeV<T> ||
                         cppgc::IsWeakMemberTypeV<T>> {};

template <typename T>
struct IsAnyMemberType
    : std::bool_constant<IsMemberOrWeakMemberType<T>::value ||
                         cppgc::IsUntracedMemberTypeV<T>> {};

IsTraceable<std::pair<T, U>>;

enum WeakHandlingFlag {};

// This is for tracing inside collections that have special support for weak
// pointers.
//
// Structure:
// - `Trace()`: Traces the contents.
// - `IsAlive()`: Returns true if the contents are still considered alive, and
// false otherwise.
//
// Default implementation for non-weak types is to use the regular non-weak
// TraceTrait. Default implementation for types with weakness is to
// delegate to sub types until reaching WeakMember or KeyValuePair which
// have defined weakness semantics.
template <WeakHandlingFlag weakness, typename T, typename Traits>
struct TraceInCollectionTrait;

kWeakHandlingTrait;

// This is used to check that DISALLOW_NEW objects are not
// stored in off-heap Vectors, HashTables etc.
IsDisallowNew;

template <>
class IsGarbageCollectedType<void> {};

template <typename T,
          bool = std::is_function<typename std::remove_const<
                     typename std::remove_pointer<T>::type>::type>::value ||
                 std::is_void<typename std::remove_const<
                     typename std::remove_pointer<T>::type>::type>::value>
class IsPointerToGarbageCollectedType {};

IsPointerToGarbageCollectedType<T *, false>;

IsStackAllocatedType;

template <typename T>
struct IsPointerToGced {};

}  // namespace WTF

IsGarbageCollectedType;

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_WTF_TYPE_TRAITS_H_