llvm/compiler-rt/lib/sanitizer_common/sanitizer_type_traits.h

//===-- sanitizer_type_traits.h ---------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Implements a subset of C++ type traits. This is so we can avoid depending
// on system C++ headers.
//
//===----------------------------------------------------------------------===//
#ifndef SANITIZER_TYPE_TRAITS_H
#define SANITIZER_TYPE_TRAITS_H

#include "sanitizer_common/sanitizer_internal_defs.h"

namespace __sanitizer {

struct true_type {};

struct false_type {};

// is_same<T, U>
//
// Type trait to compare if types are the same.
// E.g.
//
// ```
// is_same<int,int>::value - True
// is_same<int,char>::value - False
// ```
template <typename T, typename U>
struct is_same : public false_type {};

is_same<T, T>;

// conditional<B, T, F>
//
// Defines type as T if B is true or as F otherwise.
// E.g. the following is true
//
// ```
// is_same<int, conditional<true, int, double>::type>::value
// is_same<double, conditional<false, int, double>::type>::value
// ```
template <bool B, class T, class F>
struct conditional {};

conditional<false, T, F>;

template <class T>
struct remove_reference {};
remove_reference<T &>;
remove_reference<T &&>;

template <class T>
WARN_UNUSED_RESULT inline typename remove_reference<T>::type&& move(T&& t) {}

template <class T>
WARN_UNUSED_RESULT inline constexpr T&& forward(
    typename remove_reference<T>::type& t) {}

template <class T>
WARN_UNUSED_RESULT inline constexpr T&& forward(
    typename remove_reference<T>::type&& t) {}

template <class T, T v>
struct integral_constant {};

#ifndef __has_builtin
#define __has_builtin
#endif

#if __has_builtin(__is_trivially_destructible)

template <class T>
struct is_trivially_destructible
    : public integral_constant<bool, __is_trivially_destructible(T)> {};

#elif __has_builtin(__has_trivial_destructor)

template <class T>
struct is_trivially_destructible
    : public integral_constant<bool, __has_trivial_destructor(T)> {};

#else

template <class T>
struct is_trivially_destructible
    : public integral_constant<bool, /* less efficient fallback */ false> {};

#endif

#if __has_builtin(__is_trivially_copyable)

template <class T>
struct is_trivially_copyable
    : public integral_constant<bool, __is_trivially_copyable(T)> {};

#else

template <class T>
struct is_trivially_copyable
    : public integral_constant<bool, /* less efficient fallback */ false> {};

#endif

}  // namespace __sanitizer

#endif