diff --git a/libc/src/__support/CPP/functional.h b/libc/src/__support/CPP/functional.h index e346011debab10..5ddb988d331256 100644 --- a/libc/src/__support/CPP/functional.h +++ b/libc/src/__support/CPP/functional.h @@ -9,8 +9,13 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_CPP_FUNCTIONAL_H #define LLVM_LIBC_SRC_SUPPORT_CPP_FUNCTIONAL_H -#include "src/__support/CPP/type_traits.h" -#include "src/__support/CPP/utility.h" +#include "src/__support/CPP/type_traits/enable_if.h" +#include "src/__support/CPP/type_traits/is_convertible.h" +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/is_void.h" +#include "src/__support/CPP/type_traits/remove_cvref.h" +#include "src/__support/CPP/type_traits/remove_reference.h" +#include "src/__support/CPP/utility/forward.h" #include "src/__support/macros/attributes.h" #include @@ -30,7 +35,7 @@ template class function { template LIBC_INLINE static Ret callback_fn(intptr_t callable, Params... params) { return (*reinterpret_cast(callable))( - forward(params)...); + cpp::forward(params)...); } public: @@ -42,18 +47,18 @@ template class function { LIBC_INLINE function( Callable &&callable, // This is not the copy-constructor. - enable_if_t, function>::value> * = + enable_if_t, function>> * = nullptr, // Functor must be callable and return a suitable type. - enable_if_t || - is_convertible_v< + enable_if_t || + cpp::is_convertible_v< decltype(declval()(declval()...)), Ret>> * = nullptr) - : callback(callback_fn>), + : callback(callback_fn>), callable(reinterpret_cast(&callable)) {} LIBC_INLINE Ret operator()(Params... params) const { - return callback(callable, forward(params)...); + return callback(callable, cpp::forward(params)...); } LIBC_INLINE explicit operator bool() const { return callback; } diff --git a/libc/src/__support/CPP/type_traits.h b/libc/src/__support/CPP/type_traits.h index aa0a6375e20200..7794b39e0d8f4c 100644 --- a/libc/src/__support/CPP/type_traits.h +++ b/libc/src/__support/CPP/type_traits.h @@ -1,4 +1,4 @@ -//===-- Self contained C++ type traits --------------------------*- C++ -*-===// +//===-- Self contained C++ type_traits --------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,344 +6,51 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H -#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H - -#include "src/__support/macros/attributes.h" -#include "src/__support/macros/config.h" - -#include // For size_t. - -namespace __llvm_libc { -namespace cpp { - -template struct type_identity { - using type = T; -}; - -template struct enable_if; -template struct enable_if : type_identity {}; -template -using enable_if_t = typename enable_if::type; - -template struct integral_constant { - using value_type = T; - LIBC_INLINE_VAR static constexpr T value = v; -}; -using true_type = cpp::integral_constant; -using false_type = cpp::integral_constant; - -template using bool_constant = integral_constant; - -template -struct is_trivially_copyable - : public integral_constant {}; - -template -struct is_trivially_constructible - : integral_constant {}; - -template struct is_same : cpp::false_type {}; -template struct is_same : cpp::true_type {}; -template -LIBC_INLINE_VAR constexpr bool is_same_v = is_same::value; - -template struct is_const : cpp::false_type {}; -template struct is_const : cpp::true_type {}; -template -LIBC_INLINE_VAR constexpr bool is_const_v = is_const::value; - -template struct remove_cv : type_identity {}; -template struct remove_cv : type_identity {}; -template struct remove_cv : type_identity {}; -template struct remove_cv : type_identity {}; -template using remove_cv_t = typename remove_cv::type; - -template struct remove_reference : type_identity {}; -template struct remove_reference : type_identity {}; -template struct remove_reference : type_identity {}; -template -using remove_reference_t = typename remove_reference::type; - -template struct add_rvalue_reference : type_identity {}; - -template struct remove_cvref { - using type = remove_cv_t>; -}; -template using remove_cvref_t = typename remove_cvref::type; - -namespace details { -template -LIBC_INLINE constexpr bool is_unqualified_any_of() { - return (... || is_same_v, Args>); -} -} // namespace details - -template struct is_integral { - LIBC_INLINE_VAR static constexpr bool value = details::is_unqualified_any_of< - T, -#ifdef __SIZEOF_INT128__ - __int128_t, __uint128_t, -#endif - char, signed char, unsigned char, short, unsigned short, int, - unsigned int, long, unsigned long, long long, unsigned long long, bool>(); -}; -template -LIBC_INLINE_VAR constexpr bool is_integral_v = is_integral::value; - -template struct is_enum { - LIBC_INLINE_VAR static constexpr bool value = __is_enum(T); -}; -template -LIBC_INLINE_VAR constexpr bool is_enum_v = is_enum::value; - -template struct is_pointer : cpp::false_type {}; -template struct is_pointer : cpp::true_type {}; -template struct is_pointer : cpp::true_type {}; -template struct is_pointer : cpp::true_type {}; -template struct is_pointer : cpp::true_type {}; -template -LIBC_INLINE_VAR constexpr bool is_pointer_v = is_pointer::value; - -template struct is_floating_point { - LIBC_INLINE_VAR static constexpr bool value = - details::is_unqualified_any_of(); -}; -template -LIBC_INLINE_VAR constexpr bool is_floating_point_v = - is_floating_point::value; - -template struct is_arithmetic { - LIBC_INLINE_VAR static constexpr bool value = - is_integral::value || is_floating_point::value; -}; -template -LIBC_INLINE_VAR constexpr bool is_arithmetic_v = is_arithmetic::value; - -namespace details { -template ::value> -struct is_signed : integral_constant {}; -template struct is_signed : false_type {}; - -template ::value> -struct is_unsigned : integral_constant T(0))> {}; -template struct is_unsigned : false_type {}; -} // namespace details - -template struct is_signed { - LIBC_INLINE_VAR static constexpr bool value = details::is_signed::value; - LIBC_INLINE constexpr operator bool() const { return value; } - LIBC_INLINE constexpr bool operator()() const { return value; } -}; -template -LIBC_INLINE_VAR constexpr bool is_signed_v = is_signed::value; - -template struct is_unsigned { - LIBC_INLINE_VAR static constexpr bool value = details::is_unsigned::value; - LIBC_INLINE constexpr operator bool() const { return value; } - LIBC_INLINE constexpr bool operator()() const { return value; } -}; -template -LIBC_INLINE_VAR constexpr bool is_unsigned_v = is_unsigned::value; - -template struct make_unsigned; -template <> struct make_unsigned : type_identity {}; -template <> struct make_unsigned : type_identity {}; -template <> struct make_unsigned : type_identity {}; -template <> struct make_unsigned : type_identity {}; -template <> struct make_unsigned : type_identity {}; -template <> -struct make_unsigned : type_identity {}; -template <> -struct make_unsigned : type_identity {}; -template <> -struct make_unsigned : type_identity {}; -template <> struct make_unsigned : type_identity {}; -template <> -struct make_unsigned : type_identity {}; -template <> -struct make_unsigned : type_identity {}; -#ifdef __SIZEOF_INT128__ -template <> struct make_unsigned<__int128_t> : type_identity<__uint128_t> {}; -template <> struct make_unsigned<__uint128_t> : type_identity<__uint128_t> {}; -#endif -template using make_unsigned_t = typename make_unsigned::type; - -template struct make_signed; -template <> struct make_signed : type_identity {}; -template <> struct make_signed : type_identity {}; -template <> struct make_signed : type_identity {}; -template <> struct make_signed : type_identity {}; -template <> struct make_signed : type_identity {}; -template <> struct make_signed : type_identity {}; -template <> struct make_signed : type_identity {}; -template <> struct make_signed : type_identity {}; -template <> struct make_signed : type_identity {}; -template <> struct make_signed : type_identity {}; -template <> -struct make_signed : type_identity {}; -#ifdef __SIZEOF_INT128__ -template <> struct make_signed<__int128_t> : type_identity<__int128_t> {}; -template <> struct make_signed<__uint128_t> : type_identity<__int128_t> {}; -#endif -template using make_signed_t = typename make_signed::type; - -// Compile time type selection. -template -struct conditional : type_identity {}; -template -struct conditional : type_identity {}; -template -using conditional_t = typename conditional::type; - -template -struct is_void : is_same::type> {}; -template -LIBC_INLINE_VAR constexpr bool is_void_v = is_void::value; -template T declval(); - -// Compile time checks on implicit conversions. -namespace details { -template using void_t = void; -template void convertible_to_helper(T); -} // namespace details - -template -LIBC_INLINE_VAR constexpr bool is_convertible_v = false; - -// FIXME: This should use LIBC_INLINE_VAR, but clang buggily complains about -// this when LIBC_INLINE_VAR uses [[clang::internal_linkage]]. -template -constexpr bool - is_convertible_v( - declval()))>> = true; - -namespace details { -#if LIBC_HAS_BUILTIN(__is_lvalue_reference) && \ - LIBC_HAS_BUILTIN(__is_rvalue_reference) && \ - LIBC_HAS_BUILTIN(__is_reference) - -template -struct is_lvalue_reference : bool_constant<__is_lvalue_reference(T)> {}; -template -struct is_rvalue_reference : bool_constant<__is_rvalue_reference(T)> {}; -template struct is_reference : bool_constant<__is_reference(T)> {}; - -#else // LIBC_HAS_BUILTIN(__is_lvalue_reference) && etc... - -template struct is_lvalue_reference : public false_type {}; -template struct is_lvalue_reference : public true_type {}; - -template struct is_rvalue_reference : public false_type {}; -template struct is_rvalue_reference : public true_type {}; - -template struct is_reference : public false_type {}; -template struct is_reference : public true_type {}; -template struct is_reference : public true_type {}; - -#endif // LIBC_HAS_BUILTIN(__is_lvalue_reference) && etc... - -#if LIBC_HAS_BUILTIN(__remove_all_extents) -template using __remove_all_extents_t = __remove_all_extents(T); -#else -template struct remove_all_extents { - typedef T type; -}; -template struct remove_all_extents { - typedef typename remove_all_extents::type type; -}; -template struct remove_all_extents { - typedef typename remove_all_extents::type type; -}; - -template -using __remove_all_extents_t = typename remove_all_extents::type; -#endif // LIBC_HAS_BUILTIN(__remove_all_extents) - -#if LIBC_HAS_BUILTIN(__is_function) - -template -struct is_function : integral_constant {}; - -#else - -template -struct is_function - : public integral_constant::value || - is_const::value)> {}; - -#endif // LIBC_HAS_BUILTIN(__is_function) - -#if LIBC_HAS_BUILTIN(__is_destructible) - -template -struct is_destructible : bool_constant<__is_destructible(T)> {}; - -#else // LIBC_HAS_BUILTIN(__is_destructible) - -// if it's a reference, return true -// if it's a function, return false -// if it's void, return false -// if it's an array of unknown bound, return false -// Otherwise, return "declval().~T()" is well-formed -// where T is remove_all_extents::type - -template struct __is_destructible_apply { - typedef int type; -}; - -template struct __is_destructor_wellformed { - template - static true_type __test( - typename __is_destructible_apply().~T1())>::type); - - template static false_type __test(...); - - static const bool value = decltype(__test(12))::value; -}; - -template struct __destructible_imp; - -template -struct __destructible_imp - : public integral_constant< - bool, __is_destructor_wellformed<__remove_all_extents_t>::value> { -}; - -template struct __destructible_imp : public true_type {}; - -template struct __destructible_false; -template -struct __destructible_false - : public __destructible_imp::value> {}; -template -struct __destructible_false : public false_type {}; - -template -struct is_destructible : public __destructible_false::value> { -}; -template struct is_destructible : public false_type {}; -template <> struct is_destructible : public false_type {}; - -#endif // LIBC_HAS_BUILTIN(__is_destructible) -} // namespace details - -#if LIBC_HAS_BUILTIN(__is_trivially_destructible) - -template -struct is_trivially_destructible - : public integral_constant {}; - -#else -template -struct is_trivially_destructible - : public integral_constant< - bool, __llvm_libc::cpp::details::is_destructible::value - &&__has_trivial_destructor(T)> {}; -#endif // LIBC_HAS_BUILTIN(__is_trivially_destructible) - -} // namespace cpp -} // namespace __llvm_libc - -#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_H + +#include "src/__support/CPP/type_traits/add_lvalue_reference.h" +#include "src/__support/CPP/type_traits/add_pointer.h" +#include "src/__support/CPP/type_traits/add_rvalue_reference.h" +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/conditional.h" +#include "src/__support/CPP/type_traits/decay.h" +#include "src/__support/CPP/type_traits/enable_if.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/integral_constant.h" +#include "src/__support/CPP/type_traits/is_arithmetic.h" +#include "src/__support/CPP/type_traits/is_array.h" +#include "src/__support/CPP/type_traits/is_base_of.h" +#include "src/__support/CPP/type_traits/is_class.h" +#include "src/__support/CPP/type_traits/is_const.h" +#include "src/__support/CPP/type_traits/is_convertible.h" +#include "src/__support/CPP/type_traits/is_destructible.h" +#include "src/__support/CPP/type_traits/is_enum.h" +#include "src/__support/CPP/type_traits/is_floating_point.h" +#include "src/__support/CPP/type_traits/is_function.h" +#include "src/__support/CPP/type_traits/is_integral.h" +#include "src/__support/CPP/type_traits/is_lvalue_reference.h" +#include "src/__support/CPP/type_traits/is_null_pointer.h" +#include "src/__support/CPP/type_traits/is_pointer.h" +#include "src/__support/CPP/type_traits/is_reference.h" +#include "src/__support/CPP/type_traits/is_rvalue_reference.h" +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/is_signed.h" +#include "src/__support/CPP/type_traits/is_trivially_constructible.h" +#include "src/__support/CPP/type_traits/is_trivially_copyable.h" +#include "src/__support/CPP/type_traits/is_trivially_destructible.h" +#include "src/__support/CPP/type_traits/is_union.h" +#include "src/__support/CPP/type_traits/is_unsigned.h" +#include "src/__support/CPP/type_traits/is_void.h" +#include "src/__support/CPP/type_traits/make_signed.h" +#include "src/__support/CPP/type_traits/make_unsigned.h" +#include "src/__support/CPP/type_traits/remove_all_extents.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/CPP/type_traits/remove_cvref.h" +#include "src/__support/CPP/type_traits/remove_extent.h" +#include "src/__support/CPP/type_traits/remove_reference.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/CPP/type_traits/void_t.h" + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_H diff --git a/libc/src/__support/CPP/type_traits/add_lvalue_reference.h b/libc/src/__support/CPP/type_traits/add_lvalue_reference.h new file mode 100644 index 00000000000000..7cb22ac03bb033 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/add_lvalue_reference.h @@ -0,0 +1,28 @@ +//===-- add_lvalue_reference type_traits ------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ADD_LVALUE_REFERENCE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ADD_LVALUE_REFERENCE_H + +#include "src/__support/CPP/type_traits/type_identity.h" + +namespace __llvm_libc::cpp { + +// add_lvalue_reference +namespace detail { +template // Note that `cv void&` is a substitution failure +auto try_add_lvalue_reference(int) -> cpp::type_identity; +template // Handle T = cv void case +auto try_add_lvalue_reference(...) -> cpp::type_identity; +} // namespace detail +template +struct add_lvalue_reference : decltype(detail::try_add_lvalue_reference(0)) { +}; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ADD_LVALUE_REFERENCE_H diff --git a/libc/src/__support/CPP/type_traits/add_pointer.h b/libc/src/__support/CPP/type_traits/add_pointer.h new file mode 100644 index 00000000000000..543259ea1ca8f4 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/add_pointer.h @@ -0,0 +1,28 @@ +//===-- add_pointer type_traits ---------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ADD_POINTER_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ADD_POINTER_H + +#include "src/__support/CPP/type_traits/remove_reference.h" +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" + +namespace __llvm_libc::cpp { + +// add_pointer +namespace detail { +template +auto try_add_pointer(int) -> cpp::type_identity *>; +template auto try_add_pointer(...) -> cpp::type_identity; +} // namespace detail +template +struct add_pointer : decltype(detail::try_add_pointer(0)) {}; +template using add_pointer_t = typename add_pointer::type; +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ADD_POINTER_H diff --git a/libc/src/__support/CPP/type_traits/add_rvalue_reference.h b/libc/src/__support/CPP/type_traits/add_rvalue_reference.h new file mode 100644 index 00000000000000..b912cef59b68f8 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/add_rvalue_reference.h @@ -0,0 +1,29 @@ +//===-- add_rvalue_reference type_traits ------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ADD_RVALUE_REFERENCE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ADD_RVALUE_REFERENCE_H + +#include "src/__support/CPP/type_traits/type_identity.h" + +namespace __llvm_libc::cpp { + +// add_rvalue_reference +namespace detail { +template +auto try_add_rvalue_reference(int) -> cpp::type_identity; +template auto try_add_rvalue_reference(...) -> cpp::type_identity; +} // namespace detail +template +struct add_rvalue_reference : decltype(detail::try_add_rvalue_reference(0)) { +}; +template +using add_rvalue_reference_t = typename add_rvalue_reference::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ADD_RVALUE_REFERENCE_H diff --git a/libc/src/__support/CPP/type_traits/bool_constant.h b/libc/src/__support/CPP/type_traits/bool_constant.h new file mode 100644 index 00000000000000..6fcfb8e82e4d80 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/bool_constant.h @@ -0,0 +1,20 @@ +//===-- bool_constant type_traits -------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_BOOL_CONSTANT_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_BOOL_CONSTANT_H + +#include "src/__support/CPP/type_traits/integral_constant.h" + +namespace __llvm_libc::cpp { + +// bool_constant +template using bool_constant = cpp::integral_constant; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_BOOL_CONSTANT_H diff --git a/libc/src/__support/CPP/type_traits/conditional.h b/libc/src/__support/CPP/type_traits/conditional.h new file mode 100644 index 00000000000000..f9917c2a7264ce --- /dev/null +++ b/libc/src/__support/CPP/type_traits/conditional.h @@ -0,0 +1,25 @@ +//===-- conditional type_traits ---------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_CONDITIONAL_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_CONDITIONAL_H + +#include "src/__support/CPP/type_traits/type_identity.h" + +namespace __llvm_libc::cpp { + +// conditional +template +struct conditional : type_identity {}; +template +struct conditional : type_identity {}; +template +using conditional_t = typename conditional::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_CONDITIONAL_H diff --git a/libc/src/__support/CPP/type_traits/decay.h b/libc/src/__support/CPP/type_traits/decay.h new file mode 100644 index 00000000000000..f3f9cfc5eaa006 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/decay.h @@ -0,0 +1,38 @@ +//===-- decay type_traits ---------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_DECAY_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_DECAY_H + +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +#include "src/__support/CPP/type_traits/add_pointer.h" +#include "src/__support/CPP/type_traits/conditional.h" +#include "src/__support/CPP/type_traits/is_array.h" +#include "src/__support/CPP/type_traits/is_function.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/CPP/type_traits/remove_extent.h" +#include "src/__support/CPP/type_traits/remove_reference.h" + +namespace __llvm_libc::cpp { + +// decay +template class decay { + using U = cpp::remove_reference_t; + +public: + using type = conditional_t< + cpp::is_array_v, cpp::add_pointer_t>, + cpp::conditional_t, cpp::add_pointer_t, + cpp::remove_cv_t>>; +}; +template using decay_t = typename decay::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_DECAY_H diff --git a/libc/src/__support/CPP/type_traits/enable_if.h b/libc/src/__support/CPP/type_traits/enable_if.h new file mode 100644 index 00000000000000..51d7252fc3e48d --- /dev/null +++ b/libc/src/__support/CPP/type_traits/enable_if.h @@ -0,0 +1,23 @@ +//===-- enable_if type_traits -----------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ENABLE_IF_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ENABLE_IF_H + +#include "src/__support/CPP/type_traits/type_identity.h" + +namespace __llvm_libc::cpp { + +// enable_if +template struct enable_if; +template struct enable_if : type_identity {}; +template +using enable_if_t = typename enable_if::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_ENABLE_IF_H diff --git a/libc/src/__support/CPP/type_traits/false_type.h b/libc/src/__support/CPP/type_traits/false_type.h new file mode 100644 index 00000000000000..8dc6fc66d28878 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/false_type.h @@ -0,0 +1,20 @@ +//===-- false_type type_traits ----------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_FALSE_TYPE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_FALSE_TYPE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" + +namespace __llvm_libc::cpp { + +// false_type +using false_type = cpp::bool_constant; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_FALSE_TYPE_H diff --git a/libc/src/__support/CPP/type_traits/integral_constant.h b/libc/src/__support/CPP/type_traits/integral_constant.h new file mode 100644 index 00000000000000..21bdbccf073a61 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/integral_constant.h @@ -0,0 +1,23 @@ +//===-- integral_constant type_traits ---------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INTEGRAL_CONSTANT_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INTEGRAL_CONSTANT_H + +#include "src/__support/macros/attributes.h" // LIBC_INLINE_VAR + +namespace __llvm_libc::cpp { + +// integral_constant +template struct integral_constant { + using value_type = T; + LIBC_INLINE_VAR static constexpr T value = v; +}; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_INTEGRAL_CONSTANT_H diff --git a/libc/src/__support/CPP/type_traits/is_arithmetic.h b/libc/src/__support/CPP/type_traits/is_arithmetic.h new file mode 100644 index 00000000000000..cc651b11b20482 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_arithmetic.h @@ -0,0 +1,27 @@ +//===-- is_arithmetic type_traits -------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_ARITHMETIC_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_ARITHMETIC_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_floating_point.h" +#include "src/__support/CPP/type_traits/is_integral.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_arithmetic +template +struct is_arithmetic : cpp::bool_constant<(cpp::is_integral_v || + cpp::is_floating_point_v)> {}; +template +LIBC_INLINE_VAR constexpr bool is_arithmetic_v = is_arithmetic::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_ARITHMETIC_H diff --git a/libc/src/__support/CPP/type_traits/is_array.h b/libc/src/__support/CPP/type_traits/is_array.h new file mode 100644 index 00000000000000..c04a2edb6c77ef --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_array.h @@ -0,0 +1,28 @@ +//===-- is_array type_traits ------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_ARRAY_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_ARRAY_H + +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" + +#include // For size_t + +namespace __llvm_libc::cpp { + +// is_array +template struct is_array : false_type {}; +template struct is_array : true_type {}; +template struct is_array : true_type {}; +template +LIBC_INLINE_VAR constexpr bool is_array_v = is_array::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_ARRAY_H diff --git a/libc/src/__support/CPP/type_traits/is_base_of.h b/libc/src/__support/CPP/type_traits/is_base_of.h new file mode 100644 index 00000000000000..7820c83f7cbcad --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_base_of.h @@ -0,0 +1,44 @@ +//===-- is_base_of type_traits ----------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_BASE_OF_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_BASE_OF_H + +#include "src/__support/CPP/type_traits/add_rvalue_reference.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/is_class.h" +#include "src/__support/CPP/type_traits/remove_all_extents.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_base_of +namespace detail { +template cpp::true_type __test_ptr_conv(const volatile B *); +template cpp::false_type __test_ptr_conv(const volatile void *); + +template +auto is_base_of(int) -> decltype(__test_ptr_conv(static_cast(nullptr))); + +template +auto is_base_of(...) -> cpp::true_type; // private or ambiguous base + +} // namespace detail + +template +struct is_base_of + : cpp::bool_constant< + cpp::is_class_v && + cpp::is_class_v &&decltype(detail::is_base_of( + 0))::value> {}; +template +LIBC_INLINE_VAR constexpr bool is_base_of_v = is_base_of::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_BASE_OF_H diff --git a/libc/src/__support/CPP/type_traits/is_class.h b/libc/src/__support/CPP/type_traits/is_class.h new file mode 100644 index 00000000000000..93b3c3d5df33ed --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_class.h @@ -0,0 +1,29 @@ +//===-- is_class type_traits ------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_CLASS_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_CLASS_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/is_union.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_class +namespace detail { +template cpp::bool_constant> test(int T::*); +template cpp::false_type test(...); +} // namespace detail +template struct is_class : decltype(detail::test(nullptr)) {}; +template +LIBC_INLINE_VAR constexpr bool is_class_v = is_class::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_CLASS_H diff --git a/libc/src/__support/CPP/type_traits/is_const.h b/libc/src/__support/CPP/type_traits/is_const.h new file mode 100644 index 00000000000000..5434e2982d95cf --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_const.h @@ -0,0 +1,25 @@ +//===-- is_const type_traits ------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_CONST_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_CONST_H + +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_const +template struct is_const : cpp::false_type {}; +template struct is_const : cpp::true_type {}; +template +LIBC_INLINE_VAR constexpr bool is_const_v = is_const::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_CONST_H diff --git a/libc/src/__support/CPP/type_traits/is_convertible.h b/libc/src/__support/CPP/type_traits/is_convertible.h new file mode 100644 index 00000000000000..a7292c3461d484 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_convertible.h @@ -0,0 +1,45 @@ +//===-- is_convertible type_traits ------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_CONVERTIBLE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_CONVERTIBLE_H + +#include "src/__support/CPP/type_traits/is_void.h" +#include "src/__support/CPP/utility/declval.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_convertible +namespace detail { +template +auto test_returnable(int) + -> decltype(void(static_cast(nullptr)), cpp::true_type{}); +template auto test_returnable(...) -> cpp::false_type; + +template +auto test_implicitly_convertible(int) + -> decltype(void(cpp::declval()(cpp::declval())), + cpp::true_type{}); +template +auto test_implicitly_convertible(...) -> cpp::false_type; +} // namespace detail + +template +struct is_convertible + : cpp::bool_constant< + (decltype(detail::test_returnable(0))::value && + decltype(detail::test_implicitly_convertible(0))::value) || + (cpp::is_void_v && cpp::is_void_v)> {}; + +template +LIBC_INLINE_VAR constexpr bool is_convertible_v = + is_convertible::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_CONVERTIBLE_H diff --git a/libc/src/__support/CPP/type_traits/is_destructible.h b/libc/src/__support/CPP/type_traits/is_destructible.h new file mode 100644 index 00000000000000..38b64a90e4253a --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_destructible.h @@ -0,0 +1,65 @@ +//===-- is_destructible type_traits -----------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_DESTRUCTIBLE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_DESTRUCTIBLE_H + +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/is_function.h" +#include "src/__support/CPP/type_traits/is_reference.h" +#include "src/__support/CPP/type_traits/remove_all_extents.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/CPP/type_traits/type_identity.h" + +namespace __llvm_libc::cpp { + +// is_destructible +#if LIBC_HAS_BUILTIN(__is_destructible) +template +struct is_destructible : bool_constant<__is_destructible(T)> {}; +#else +// if it's a reference, return true +// if it's a function, return false +// if it's void, return false +// if it's an array of unknown bound, return false +// Otherwise, return "declval().~T()" is well-formed +// where T is remove_all_extents::type +template struct __is_destructible_apply : cpp::type_identity {}; +template struct __is_destructor_wellformed { + template + static cpp::true_type __test( + typename __is_destructible_apply().~T1())>::type); + template static cpp::false_type __test(...); + static const bool value = decltype(__test(12))::value; +}; +template struct __destructible_imp; +template +struct __destructible_imp + : public bool_constant< + __is_destructor_wellformed>::value> {}; +template +struct __destructible_imp : public cpp::true_type {}; +template struct __destructible_false; +template +struct __destructible_false + : public __destructible_imp::value> {}; +template +struct __destructible_false : public cpp::false_type {}; +template +struct is_destructible : public __destructible_false::value> { +}; +template struct is_destructible : public false_type {}; +template <> struct is_destructible : public false_type {}; +#endif + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_DESTRUCTIBLE_H diff --git a/libc/src/__support/CPP/type_traits/is_enum.h b/libc/src/__support/CPP/type_traits/is_enum.h new file mode 100644 index 00000000000000..4914df30c3cd11 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_enum.h @@ -0,0 +1,23 @@ +//===-- is_enum type_traits -------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_ENUM_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_ENUM_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_enum +template struct is_enum : bool_constant<__is_enum(T)> {}; +template +LIBC_INLINE_VAR constexpr bool is_enum_v = is_enum::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_ENUM_H diff --git a/libc/src/__support/CPP/type_traits/is_floating_point.h b/libc/src/__support/CPP/type_traits/is_floating_point.h new file mode 100644 index 00000000000000..746d0e36c92eba --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_floating_point.h @@ -0,0 +1,35 @@ +//===-- is_floating_point type_traits ---------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H + +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_floating_point +template struct is_floating_point { +private: + template + LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() { + return (... || is_same_v, Args>); + } + +public: + LIBC_INLINE_VAR static constexpr bool value = + __is_unqualified_any_of(); +}; +template +LIBC_INLINE_VAR constexpr bool is_floating_point_v = + is_floating_point::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_FLOATING_POINT_H diff --git a/libc/src/__support/CPP/type_traits/is_function.h b/libc/src/__support/CPP/type_traits/is_function.h new file mode 100644 index 00000000000000..3a8b3486e8f3ad --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_function.h @@ -0,0 +1,33 @@ +//===-- is_function type_traits ---------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_FUNCTION_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_FUNCTION_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_const.h" +#include "src/__support/CPP/type_traits/is_reference.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace __llvm_libc::cpp { + +// is_function +#if LIBC_HAS_BUILTIN(__is_function) +template +struct is_function : integral_constant {}; +#else +template +struct is_function + : public bool_constant || is_const_v)> {}; +#endif +template +LIBC_INLINE_VAR constexpr bool is_function_v = is_function::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_FUNCTION_H diff --git a/libc/src/__support/CPP/type_traits/is_integral.h b/libc/src/__support/CPP/type_traits/is_integral.h new file mode 100644 index 00000000000000..0113a5bf911393 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_integral.h @@ -0,0 +1,39 @@ +//===-- is_integral type_traits ---------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_INTEGRAL_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_INTEGRAL_H + +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_integral +template struct is_integral { +private: + template + LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() { + return (... || is_same_v, Args>); + } + +public: + LIBC_INLINE_VAR static constexpr bool value = __is_unqualified_any_of< + T, +#ifdef __SIZEOF_INT128__ + __int128_t, __uint128_t, +#endif + char, signed char, unsigned char, short, unsigned short, int, + unsigned int, long, unsigned long, long long, unsigned long long, bool>(); +}; +template +LIBC_INLINE_VAR constexpr bool is_integral_v = is_integral::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_INTEGRAL_H diff --git a/libc/src/__support/CPP/type_traits/is_lvalue_reference.h b/libc/src/__support/CPP/type_traits/is_lvalue_reference.h new file mode 100644 index 00000000000000..fe7f4f7252530f --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_lvalue_reference.h @@ -0,0 +1,33 @@ +//===-- is_lvalue_reference type_traits -------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_LVALUE_REFERENCE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_LVALUE_REFERENCE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace __llvm_libc::cpp { + +// is_lvalue_reference +#if LIBC_HAS_BUILTIN(__is_lvalue_reference) +template +struct is_lvalue_reference : bool_constant<__is_lvalue_reference(T)> {}; +#else +template struct is_lvalue_reference : public false_type {}; +template struct is_lvalue_reference : public true_type {}; +#endif +template +LIBC_INLINE_VAR constexpr bool is_lvalue_reference_v = + is_lvalue_reference::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_LVALUE_REFERENCE_H diff --git a/libc/src/__support/CPP/type_traits/is_null_pointer.h b/libc/src/__support/CPP/type_traits/is_null_pointer.h new file mode 100644 index 00000000000000..e5c024b1b3898b --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_null_pointer.h @@ -0,0 +1,24 @@ +//===-- is_null_pointer type_traits -----------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_NULL_POINTER_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_NULL_POINTER_H + +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_null_pointer +using nullptr_t = decltype(nullptr); +template +struct is_null_pointer : cpp::is_same> {}; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_NULL_POINTER_H diff --git a/libc/src/__support/CPP/type_traits/is_pointer.h b/libc/src/__support/CPP/type_traits/is_pointer.h new file mode 100644 index 00000000000000..f7af8752e8d899 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_pointer.h @@ -0,0 +1,28 @@ +//===-- is_pointer type_traits ----------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_POINTER_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_POINTER_H + +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_pointer +template struct is_pointer : cpp::false_type {}; +template struct is_pointer : cpp::true_type {}; +template struct is_pointer : cpp::true_type {}; +template struct is_pointer : cpp::true_type {}; +template struct is_pointer : cpp::true_type {}; +template +LIBC_INLINE_VAR constexpr bool is_pointer_v = is_pointer::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_POINTER_H diff --git a/libc/src/__support/CPP/type_traits/is_reference.h b/libc/src/__support/CPP/type_traits/is_reference.h new file mode 100644 index 00000000000000..147b65ebfe7b78 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_reference.h @@ -0,0 +1,29 @@ +//===-- is_reference type_traits --------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_REFERENCE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_REFERENCE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/config.h" + +namespace __llvm_libc::cpp { + +// is_reference +#if LIBC_HAS_BUILTIN(__is_reference) +template struct is_reference : bool_constant<__is_reference(T)> {}; +#else +template struct is_reference : public false_type {}; +template struct is_reference : public true_type {}; +template struct is_reference : public true_type {}; +#endif + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_REFERENCE_H diff --git a/libc/src/__support/CPP/type_traits/is_rvalue_reference.h b/libc/src/__support/CPP/type_traits/is_rvalue_reference.h new file mode 100644 index 00000000000000..33b2037df01381 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_rvalue_reference.h @@ -0,0 +1,32 @@ +//===-- is_rvalue_reference type_traits -------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_RVALUE_REFERENCE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_RVALUE_REFERENCE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace __llvm_libc::cpp { + +// is_rvalue_reference +#if LIBC_HAS_BUILTIN(__is_rvalue_reference) +template +struct is_rvalue_reference : bool_constant<__is_rvalue_reference(T)> {}; +#else +template struct is_rvalue_reference : public false_type {}; +template struct is_rvalue_reference : public true_type {}; +#endif +template +using add_rvalue_reference_t = typename add_rvalue_reference::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_RVALUE_REFERENCE_H diff --git a/libc/src/__support/CPP/type_traits/is_same.h b/libc/src/__support/CPP/type_traits/is_same.h new file mode 100644 index 00000000000000..f8fa7ed2f350c6 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_same.h @@ -0,0 +1,25 @@ +//===-- is_same type_traits -------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_SAME_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_SAME_H + +#include "src/__support/CPP/type_traits/false_type.h" +#include "src/__support/CPP/type_traits/true_type.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_same +template struct is_same : cpp::false_type {}; +template struct is_same : cpp::true_type {}; +template +LIBC_INLINE_VAR constexpr bool is_same_v = is_same::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_SAME_H diff --git a/libc/src/__support/CPP/type_traits/is_signed.h b/libc/src/__support/CPP/type_traits/is_signed.h new file mode 100644 index 00000000000000..a4e6dbcf3d62e7 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_signed.h @@ -0,0 +1,28 @@ +//===-- is_signed type_traits -----------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_arithmetic.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_signed +template +struct is_signed : bool_constant<(is_arithmetic_v && (T(-1) < T(0)))> { + LIBC_INLINE constexpr operator bool() const { return is_signed::value; } + LIBC_INLINE constexpr bool operator()() const { return is_signed::value; } +}; +template +LIBC_INLINE_VAR constexpr bool is_signed_v = is_signed::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H diff --git a/libc/src/__support/CPP/type_traits/is_trivially_constructible.h b/libc/src/__support/CPP/type_traits/is_trivially_constructible.h new file mode 100644 index 00000000000000..3053e7b9ac53b7 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_trivially_constructible.h @@ -0,0 +1,22 @@ +//===-- is_trivially_constructible type_traits ------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H + +#include "src/__support/CPP/type_traits/integral_constant.h" + +namespace __llvm_libc::cpp { + +// is_trivially_constructible +template +struct is_trivially_constructible + : integral_constant {}; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_CONSTRUCTIBLE_H diff --git a/libc/src/__support/CPP/type_traits/is_trivially_copyable.h b/libc/src/__support/CPP/type_traits/is_trivially_copyable.h new file mode 100644 index 00000000000000..a1b5a0cb26c5fc --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_trivially_copyable.h @@ -0,0 +1,23 @@ +//===-- is_trivially_copyable type_traits -----------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H + +#include "src/__support/CPP/type_traits/integral_constant.h" +#include "src/__support/macros/config.h" + +namespace __llvm_libc::cpp { + +// is_trivially_copyable +template +struct is_trivially_copyable + : public integral_constant {}; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_COPYABLE_H diff --git a/libc/src/__support/CPP/type_traits/is_trivially_destructible.h b/libc/src/__support/CPP/type_traits/is_trivially_destructible.h new file mode 100644 index 00000000000000..5eab5aa0846043 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_trivially_destructible.h @@ -0,0 +1,35 @@ +//===-- is_trivially_destructible type_traits -------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_destructible.h" +#include "src/__support/macros/attributes.h" +#include "src/__support/macros/config.h" + +namespace __llvm_libc::cpp { + +// is_trivially_destructible +#if LIBC_HAS_BUILTIN(__is_trivially_destructible) +template +struct is_trivially_destructible + : public bool_constant<__is_trivially_destructible(T)> {}; +#else +template +struct is_trivially_destructible + : public bool_constant &&__has_trivial_destructor( + T)> {}; +#endif // LIBC_HAS_BUILTIN(__is_trivially_destructible) +template +LIBC_INLINE_VAR constexpr bool is_trivially_destructible_v = + is_trivially_destructible::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_TRIVIALLY_DESTRUCTIBLE_H diff --git a/libc/src/__support/CPP/type_traits/is_union.h b/libc/src/__support/CPP/type_traits/is_union.h new file mode 100644 index 00000000000000..354dbd160844b3 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_union.h @@ -0,0 +1,23 @@ +//===-- is_union type_traits ------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_UNION_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_UNION_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_union +template struct is_union : bool_constant<__is_union(T)> {}; +template +LIBC_INLINE_VAR constexpr bool is_union_v = is_union::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_UNION_H diff --git a/libc/src/__support/CPP/type_traits/is_unsigned.h b/libc/src/__support/CPP/type_traits/is_unsigned.h new file mode 100644 index 00000000000000..6510c1304cf344 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_unsigned.h @@ -0,0 +1,28 @@ +//===-- is_unsigned type_traits ---------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_UNSIGNED_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_UNSIGNED_H + +#include "src/__support/CPP/type_traits/bool_constant.h" +#include "src/__support/CPP/type_traits/is_arithmetic.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_unsigned +template +struct is_unsigned : bool_constant<(is_arithmetic_v && (T(-1) > T(0)))> { + LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; } + LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; } +}; +template +LIBC_INLINE_VAR constexpr bool is_unsigned_v = is_unsigned::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_UNSIGNED_H diff --git a/libc/src/__support/CPP/type_traits/is_void.h b/libc/src/__support/CPP/type_traits/is_void.h new file mode 100644 index 00000000000000..be054f0860c26c --- /dev/null +++ b/libc/src/__support/CPP/type_traits/is_void.h @@ -0,0 +1,24 @@ +//===-- is_void type_traits -------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_VOID_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_VOID_H + +#include "src/__support/CPP/type_traits/is_same.h" +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// is_void +template struct is_void : is_same> {}; +template +LIBC_INLINE_VAR constexpr bool is_void_v = is_void::value; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_IS_VOID_H diff --git a/libc/src/__support/CPP/type_traits/make_signed.h b/libc/src/__support/CPP/type_traits/make_signed.h new file mode 100644 index 00000000000000..c896c459023253 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/make_signed.h @@ -0,0 +1,37 @@ +//===-- make_signed type_traits ---------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_MAKE_SIGNED_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_MAKE_SIGNED_H + +#include "src/__support/CPP/type_traits/type_identity.h" + +namespace __llvm_libc::cpp { + +// make_signed +template struct make_signed; +template <> struct make_signed : type_identity {}; +template <> struct make_signed : type_identity {}; +template <> struct make_signed : type_identity {}; +template <> struct make_signed : type_identity {}; +template <> struct make_signed : type_identity {}; +template <> struct make_signed : type_identity {}; +template <> struct make_signed : type_identity {}; +template <> struct make_signed : type_identity {}; +template <> struct make_signed : type_identity {}; +template <> struct make_signed : type_identity {}; +template <> +struct make_signed : type_identity {}; +#ifdef __SIZEOF_INT128__ +template <> struct make_signed<__int128_t> : type_identity<__int128_t> {}; +template <> struct make_signed<__uint128_t> : type_identity<__int128_t> {}; +#endif +template using make_signed_t = typename make_signed::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_MAKE_SIGNED_H diff --git a/libc/src/__support/CPP/type_traits/make_unsigned.h b/libc/src/__support/CPP/type_traits/make_unsigned.h new file mode 100644 index 00000000000000..5cd7c3cd4c8639 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/make_unsigned.h @@ -0,0 +1,42 @@ +//===-- make_unsigned type_traits -------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_MAKE_UNSIGNED_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_MAKE_UNSIGNED_H + +#include "src/__support/CPP/type_traits/type_identity.h" + +namespace __llvm_libc::cpp { + +// make_unsigned + +template struct make_unsigned; +template <> struct make_unsigned : type_identity {}; +template <> struct make_unsigned : type_identity {}; +template <> struct make_unsigned : type_identity {}; +template <> struct make_unsigned : type_identity {}; +template <> struct make_unsigned : type_identity {}; +template <> +struct make_unsigned : type_identity {}; +template <> +struct make_unsigned : type_identity {}; +template <> +struct make_unsigned : type_identity {}; +template <> struct make_unsigned : type_identity {}; +template <> +struct make_unsigned : type_identity {}; +template <> +struct make_unsigned : type_identity {}; +#ifdef __SIZEOF_INT128__ +template <> struct make_unsigned<__int128_t> : type_identity<__uint128_t> {}; +template <> struct make_unsigned<__uint128_t> : type_identity<__uint128_t> {}; +#endif +template using make_unsigned_t = typename make_unsigned::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_MAKE_UNSIGNED_H diff --git a/libc/src/__support/CPP/type_traits/remove_all_extents.h b/libc/src/__support/CPP/type_traits/remove_all_extents.h new file mode 100644 index 00000000000000..7799032ad52556 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/remove_all_extents.h @@ -0,0 +1,37 @@ +//===-- remove_all_extents type_traits --------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_ALL_EXTENTS_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_ALL_EXTENTS_H + +#include "src/__support/CPP/type_traits/type_identity.h" +#include "src/__support/macros/config.h" + +namespace __llvm_libc::cpp { + +// remove_all_extents +#if LIBC_HAS_BUILTIN(__remove_all_extents) +template using remove_all_extents_t = __remove_all_extents(T); +template +struct remove_all_extents : cpp::type_identity> {}; +#else +template struct remove_all_extents { + using type = T; +}; +template struct remove_all_extents { + using type = typename remove_all_extents::type; +}; +template struct remove_all_extents { + using type = typename remove_all_extents::type; +}; +template +using remove_all_extents_t = typename remove_all_extents::type; +#endif + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_ALL_EXTENTS_H diff --git a/libc/src/__support/CPP/type_traits/remove_cv.h b/libc/src/__support/CPP/type_traits/remove_cv.h new file mode 100644 index 00000000000000..8ce41d64de277f --- /dev/null +++ b/libc/src/__support/CPP/type_traits/remove_cv.h @@ -0,0 +1,25 @@ +//===-- remove_cv type_traits -----------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_CV_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_CV_H + +#include "src/__support/CPP/type_traits/type_identity.h" + +namespace __llvm_libc::cpp { + +// remove_cv +template struct remove_cv : cpp::type_identity {}; +template struct remove_cv : cpp::type_identity {}; +template struct remove_cv : cpp::type_identity {}; +template +struct remove_cv : cpp::type_identity {}; +template using remove_cv_t = typename remove_cv::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_CV_H diff --git a/libc/src/__support/CPP/type_traits/remove_cvref.h b/libc/src/__support/CPP/type_traits/remove_cvref.h new file mode 100644 index 00000000000000..68eb479f548d4a --- /dev/null +++ b/libc/src/__support/CPP/type_traits/remove_cvref.h @@ -0,0 +1,24 @@ +//===-- remove_cvref type_traits --------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_CVREF_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_CVREF_H + +#include "src/__support/CPP/type_traits/remove_cv.h" +#include "src/__support/CPP/type_traits/remove_reference.h" + +namespace __llvm_libc::cpp { + +// remove_cvref +template struct remove_cvref { + using type = remove_cv_t>; +}; +template using remove_cvref_t = typename remove_cvref::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_CVREF_H diff --git a/libc/src/__support/CPP/type_traits/remove_extent.h b/libc/src/__support/CPP/type_traits/remove_extent.h new file mode 100644 index 00000000000000..cc92f8fd080bf2 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/remove_extent.h @@ -0,0 +1,24 @@ +//===-- remove_extent type_traits -------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_EXTENT_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_EXTENT_H + +#include "src/__support/CPP/type_traits/type_identity.h" + +namespace __llvm_libc::cpp { + +// remove_extent +template struct remove_extent : cpp::type_identity {}; +template struct remove_extent : cpp::type_identity {}; +template +struct remove_extent : cpp::type_identity {}; +template using remove_extent_t = typename remove_extent::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_EXTENT_H diff --git a/libc/src/__support/CPP/type_traits/remove_reference.h b/libc/src/__support/CPP/type_traits/remove_reference.h new file mode 100644 index 00000000000000..b1cb1767927382 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/remove_reference.h @@ -0,0 +1,24 @@ +//===-- remove_reference type_traits ----------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_REFERENCE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_REFERENCE_H + +#include "src/__support/CPP/type_traits/type_identity.h" + +namespace __llvm_libc::cpp { + +// remove_reference +template struct remove_reference : cpp::type_identity {}; +template struct remove_reference : cpp::type_identity {}; +template struct remove_reference : cpp::type_identity {}; +template +using remove_reference_t = typename remove_reference::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_REMOVE_REFERENCE_H diff --git a/libc/src/__support/CPP/type_traits/true_type.h b/libc/src/__support/CPP/type_traits/true_type.h new file mode 100644 index 00000000000000..41f1fcadf18950 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/true_type.h @@ -0,0 +1,20 @@ +//===-- true_type type_traits -----------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_TRUE_TYPE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_TRUE_TYPE_H + +#include "src/__support/CPP/type_traits/bool_constant.h" + +namespace __llvm_libc::cpp { + +// true_type +using true_type = cpp::bool_constant; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_TRUE_TYPE_H diff --git a/libc/src/__support/CPP/type_traits/type_identity.h b/libc/src/__support/CPP/type_traits/type_identity.h new file mode 100644 index 00000000000000..eaba0a9fbec47f --- /dev/null +++ b/libc/src/__support/CPP/type_traits/type_identity.h @@ -0,0 +1,20 @@ +//===-- type_identity type_traits -------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_TYPE_IDENTITY_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_TYPE_IDENTITY_H + +namespace __llvm_libc::cpp { + +// type_identity +template struct type_identity { + using type = T; +}; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_TYPE_IDENTITY_H diff --git a/libc/src/__support/CPP/type_traits/void_t.h b/libc/src/__support/CPP/type_traits/void_t.h new file mode 100644 index 00000000000000..237e7ce9744151 --- /dev/null +++ b/libc/src/__support/CPP/type_traits/void_t.h @@ -0,0 +1,26 @@ +//===-- void_t type_traits --------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_VOID_T_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_VOID_T_H + +#include "src/__support/CPP/type_traits/type_identity.h" + +namespace __llvm_libc::cpp { + +// void_t + +namespace detail { +template struct make_void : cpp::type_identity {}; +} // namespace detail + +template +using void_t = typename detail::make_void::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPE_TRAITS_VOID_T_H diff --git a/libc/src/__support/CPP/utility.h b/libc/src/__support/CPP/utility.h index 40455d5e61f879..105d3a21dc2b00 100644 --- a/libc/src/__support/CPP/utility.h +++ b/libc/src/__support/CPP/utility.h @@ -9,48 +9,9 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_H #define LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_H -#include "src/__support/CPP/type_traits.h" -#include "src/__support/macros/attributes.h" - -namespace __llvm_libc::cpp { - -template struct integer_sequence { - static_assert(is_integral_v); - template using append = integer_sequence; -}; - -namespace internal { - -template struct make_integer_sequence { - using type = - typename make_integer_sequence::type::template append; -}; - -template struct make_integer_sequence { - using type = integer_sequence; -}; - -} // namespace internal - -template -using make_integer_sequence = - typename internal::make_integer_sequence::type; - -template -LIBC_INLINE constexpr T &&forward(typename remove_reference::type &value) { - return static_cast(value); -} - -template -LIBC_INLINE constexpr T &&forward(typename remove_reference::type &&value) { - return static_cast(value); -} - -template -LIBC_INLINE constexpr typename remove_reference::type &&move(T &&value) { - return static_cast::type &&>(value); -} - -} // namespace __llvm_libc::cpp +#include "src/__support/CPP/utility/declval.h" +#include "src/__support/CPP/utility/forward.h" +#include "src/__support/CPP/utility/integer_sequence.h" +#include "src/__support/CPP/utility/move.h" #endif // LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_H diff --git a/libc/src/__support/CPP/utility/declval.h b/libc/src/__support/CPP/utility/declval.h new file mode 100644 index 00000000000000..9261ceb9332d51 --- /dev/null +++ b/libc/src/__support/CPP/utility/declval.h @@ -0,0 +1,28 @@ +//===-- declval utility -----------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_DECLVAL_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_DECLVAL_H + +#include "src/__support/CPP/type_traits/add_rvalue_reference.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// declval +namespace detail { +template LIBC_INLINE_VAR constexpr bool always_false = false; +} + +template cpp::add_rvalue_reference_t declval() { + static_assert(detail::always_false, + "declval not allowed in an evaluated context"); +} + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_DECLVAL_H diff --git a/libc/src/__support/CPP/utility/forward.h b/libc/src/__support/CPP/utility/forward.h new file mode 100644 index 00000000000000..a6698a589cb40e --- /dev/null +++ b/libc/src/__support/CPP/utility/forward.h @@ -0,0 +1,32 @@ +//===-- forward utility -----------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_FORWARD_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_FORWARD_H + +#include "src/__support/CPP/type_traits/is_lvalue_reference.h" +#include "src/__support/CPP/type_traits/remove_reference.h" +#include "src/__support/macros/attributes.h" + +namespace __llvm_libc::cpp { + +// forward +template +LIBC_INLINE constexpr T &&forward(remove_reference_t &value) { + return static_cast(value); +} + +template +LIBC_INLINE constexpr T &&forward(remove_reference_t &&value) { + static_assert(!is_lvalue_reference_v, + "cannot forward an rvalue as an lvalue"); + return static_cast(value); +} + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_FORWARD_H diff --git a/libc/src/__support/CPP/utility/integer_sequence.h b/libc/src/__support/CPP/utility/integer_sequence.h new file mode 100644 index 00000000000000..471567f714f882 --- /dev/null +++ b/libc/src/__support/CPP/utility/integer_sequence.h @@ -0,0 +1,37 @@ +//===-- integer_sequence utility --------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H + +#include "src/__support/CPP/type_traits/is_integral.h" + +namespace __llvm_libc::cpp { + +// integer_sequence +template struct integer_sequence { + static_assert(cpp::is_integral_v); + template using append = integer_sequence; +}; + +namespace detail { +template struct make_integer_sequence { + using type = + typename make_integer_sequence::type::template append; +}; +template struct make_integer_sequence { + using type = integer_sequence; +}; +} // namespace detail + +template +using make_integer_sequence = + typename detail::make_integer_sequence::type; + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_INTEGER_SEQUENCE_H diff --git a/libc/src/__support/CPP/utility/move.h b/libc/src/__support/CPP/utility/move.h new file mode 100644 index 00000000000000..3cc73c76ce9aff --- /dev/null +++ b/libc/src/__support/CPP/utility/move.h @@ -0,0 +1,22 @@ +//===-- move utility --------------------------------------------*- 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 +// +//===----------------------------------------------------------------------===// +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_MOVE_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_MOVE_H + +#include "src/__support/CPP/type_traits/remove_reference.h" + +namespace __llvm_libc::cpp { + +// move +template constexpr cpp::remove_reference_t &&move(T &&t) { + return static_cast &&>(t); +} + +} // namespace __llvm_libc::cpp + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_MOVE_H diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 32f627405ad3be..bdf260a783baa2 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -284,7 +284,53 @@ libc_support_library( libc_support_library( name = "__support_cpp_type_traits", - hdrs = ["src/__support/CPP/type_traits.h"], + hdrs = [ + "src/__support/CPP/type_traits.h", + "src/__support/CPP/type_traits/add_lvalue_reference.h", + "src/__support/CPP/type_traits/add_pointer.h", + "src/__support/CPP/type_traits/add_rvalue_reference.h", + "src/__support/CPP/type_traits/bool_constant.h", + "src/__support/CPP/type_traits/conditional.h", + "src/__support/CPP/type_traits/decay.h", + "src/__support/CPP/type_traits/enable_if.h", + "src/__support/CPP/type_traits/false_type.h", + "src/__support/CPP/type_traits/integral_constant.h", + "src/__support/CPP/type_traits/is_arithmetic.h", + "src/__support/CPP/type_traits/is_array.h", + "src/__support/CPP/type_traits/is_base_of.h", + "src/__support/CPP/type_traits/is_class.h", + "src/__support/CPP/type_traits/is_const.h", + "src/__support/CPP/type_traits/is_convertible.h", + "src/__support/CPP/type_traits/is_destructible.h", + "src/__support/CPP/type_traits/is_enum.h", + "src/__support/CPP/type_traits/is_floating_point.h", + "src/__support/CPP/type_traits/is_function.h", + "src/__support/CPP/type_traits/is_integral.h", + "src/__support/CPP/type_traits/is_lvalue_reference.h", + "src/__support/CPP/type_traits/is_null_pointer.h", + "src/__support/CPP/type_traits/is_pointer.h", + "src/__support/CPP/type_traits/is_reference.h", + "src/__support/CPP/type_traits/is_rvalue_reference.h", + "src/__support/CPP/type_traits/is_same.h", + "src/__support/CPP/type_traits/is_signed.h", + "src/__support/CPP/type_traits/is_trivially_constructible.h", + "src/__support/CPP/type_traits/is_trivially_copyable.h", + "src/__support/CPP/type_traits/is_trivially_destructible.h", + "src/__support/CPP/type_traits/is_union.h", + "src/__support/CPP/type_traits/is_unsigned.h", + "src/__support/CPP/type_traits/is_void.h", + "src/__support/CPP/type_traits/make_signed.h", + "src/__support/CPP/type_traits/make_unsigned.h", + "src/__support/CPP/type_traits/remove_all_extents.h", + "src/__support/CPP/type_traits/remove_cv.h", + "src/__support/CPP/type_traits/remove_cvref.h", + "src/__support/CPP/type_traits/remove_extent.h", + "src/__support/CPP/type_traits/remove_reference.h", + "src/__support/CPP/type_traits/true_type.h", + "src/__support/CPP/type_traits/type_identity.h", + "src/__support/CPP/type_traits/void_t.h", + "src/__support/CPP/utility/declval.h", + ], deps = [ ":__support_macros_attributes", ":__support_macros_config", @@ -294,7 +340,13 @@ libc_support_library( libc_support_library( name = "__support_cpp_utility", - hdrs = ["src/__support/CPP/utility.h"], + hdrs = [ + "src/__support/CPP/utility.h", + "src/__support/CPP/utility/declval.h", + "src/__support/CPP/utility/forward.h", + "src/__support/CPP/utility/integer_sequence.h", + "src/__support/CPP/utility/move.h", + ], deps = [ ":__support_cpp_type_traits", ":__support_macros_attributes",