diff --git a/libc/fuzzing/math/Compare.h b/libc/fuzzing/math/Compare.h --- a/libc/fuzzing/math/Compare.h +++ b/libc/fuzzing/math/Compare.h @@ -9,12 +9,11 @@ #ifndef LLVM_LIBC_FUZZING_MATH_COMPARE_H #define LLVM_LIBC_FUZZING_MATH_COMPARE_H -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/FPBits.h" template -__llvm_libc::cpp::EnableIfType<__llvm_libc::cpp::IsFloatingPointType::Value, - bool> +__llvm_libc::cpp::enable_if_t<__llvm_libc::cpp::is_floating_point_v, bool> ValuesEqual(T x1, T x2) { __llvm_libc::fputil::FPBits bits1(x1); __llvm_libc::fputil::FPBits bits2(x2); @@ -27,7 +26,7 @@ } template -__llvm_libc::cpp::EnableIfType<__llvm_libc::cpp::IsIntegral::Value, bool> +__llvm_libc::cpp::enable_if_t<__llvm_libc::cpp::is_integral_v, bool> ValuesEqual(T x1, T x2) { return x1 == x1; } diff --git a/libc/src/__support/CPP/ArrayRef.h b/libc/src/__support/CPP/ArrayRef.h --- a/libc/src/__support/CPP/ArrayRef.h +++ b/libc/src/__support/CPP/ArrayRef.h @@ -10,7 +10,7 @@ #define LLVM_LIBC_SRC_SUPPORT_CPP_ARRAYREF_H #include "Array.h" -#include "TypeTraits.h" //RemoveCVType +#include "type_traits.h" // RemoveCVType #include // For size_t. @@ -24,7 +24,7 @@ namespace internal { template class ArrayRefBase { public: - using value_type = RemoveCVType; + using value_type = remove_cv_t; using pointer = value_type *; using const_pointer = const value_type *; using reference = value_type &; @@ -109,7 +109,7 @@ template struct ArrayRef : public internal::ArrayRefBase { private: - static_assert(IsSameV>, + static_assert(is_same_v>, "ArrayRef must have a non-const, non-volatile value_type"); using Impl = internal::ArrayRefBase; using Impl::Impl; @@ -128,7 +128,7 @@ struct MutableArrayRef : public internal::ArrayRefBase { private: static_assert( - IsSameV>, + is_same_v>, "MutableArrayRef must have a non-const, non-volatile value_type"); using Impl = internal::ArrayRefBase; using Impl::Impl; diff --git a/libc/src/__support/CPP/CMakeLists.txt b/libc/src/__support/CPP/CMakeLists.txt --- a/libc/src/__support/CPP/CMakeLists.txt +++ b/libc/src/__support/CPP/CMakeLists.txt @@ -71,7 +71,7 @@ add_header_library( type_traits HDRS - TypeTraits.h + type_traits.h DEPENDS .uint ) diff --git a/libc/src/__support/CPP/TypeTraits.h b/libc/src/__support/CPP/TypeTraits.h deleted file mode 100644 --- a/libc/src/__support/CPP/TypeTraits.h +++ /dev/null @@ -1,157 +0,0 @@ -//===-- 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. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H -#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H - -#include "UInt.h" - -namespace __llvm_libc { -namespace cpp { - -template struct EnableIf; -template struct EnableIf { - typedef T Type; -}; - -template -using EnableIfType = typename EnableIf::Type; - -struct TrueValue { - static constexpr bool Value = true; -}; - -struct FalseValue { - static constexpr bool Value = false; -}; - -template struct TypeIdentity { - typedef T Type; -}; - -template struct IsSame : public FalseValue {}; -template struct IsSame : public TrueValue {}; -template -static constexpr bool IsSameV = IsSame::Value; - -template struct RemoveCV : public TypeIdentity {}; -template struct RemoveCV : public TypeIdentity {}; -template struct RemoveCV : public TypeIdentity {}; -template -struct RemoveCV : public TypeIdentity {}; - -template using RemoveCVType = typename RemoveCV::Type; - -template struct IsIntegral { - using TypeNoCV = RemoveCVType; - static constexpr bool Value = - IsSameV || IsSameV || - IsSameV || IsSameV || - IsSameV || IsSameV || - IsSameV || IsSameV || - IsSameV || IsSameV || - IsSameV || IsSameV || - // We need to include UInt<128> and __uint128_t when available because - // we want to unittest UInt<128>. If we include only UInt128, then on - // platform where it resolves to __uint128_t, we cannot unittest - // UInt<128>. - IsSameV<__llvm_libc::cpp::UInt<128>, TypeNoCV> -#ifdef __SIZEOF_INT128__ - || IsSameV<__int128_t, TypeNoCV> || IsSameV<__uint128_t, TypeNoCV> -#endif - ; -}; - -template struct IsEnum { - static constexpr bool Value = __is_enum(Type); -}; - -template struct IsPointerTypeNoCV : public FalseValue {}; -template struct IsPointerTypeNoCV : public TrueValue {}; -template struct IsPointerType { - static constexpr bool Value = IsPointerTypeNoCV>::Value; -}; - -template struct IsFloatingPointType { - using TypeNoCV = RemoveCVType; - static constexpr bool Value = IsSame::Value || - IsSame::Value || - IsSame::Value; -}; - -template struct IsArithmetic { - static constexpr bool Value = - IsIntegral::Value || IsFloatingPointType::Value; -}; - -template struct IsSigned { - static constexpr bool Value = - IsArithmetic::Value && (Type(-1) < Type(0)); - constexpr operator bool() const { return Value; } - constexpr bool operator()() const { return Value; } -}; - -template struct MakeUnsigned; -template <> struct MakeUnsigned { - using Type = unsigned char; -}; -template <> struct MakeUnsigned { - using Type = unsigned char; -}; -template <> struct MakeUnsigned { - using Type = unsigned short; -}; -template <> struct MakeUnsigned { - using Type = unsigned int; -}; -template <> struct MakeUnsigned { - using Type = unsigned long; -}; -template <> struct MakeUnsigned { - using Type = unsigned long long; -}; -template <> struct MakeUnsigned { - using Type = unsigned char; -}; -template <> struct MakeUnsigned { - using Type = unsigned short; -}; -template <> struct MakeUnsigned { - using Type = unsigned int; -}; -template <> struct MakeUnsigned { - using Type = unsigned long; -}; -template <> struct MakeUnsigned { - using Type = unsigned long long; -}; -#ifdef __SIZEOF_INT128__ -template <> struct MakeUnsigned<__int128_t> { - using Type = __uint128_t; -}; -template <> struct MakeUnsigned<__uint128_t> { - using Type = __uint128_t; -}; -#endif - -template using MakeUnsignedType = typename MakeUnsigned::Type; - -// Compile time type selection. -template struct Conditional { - using type = TrueT; -}; -template struct Conditional { - using type = FalseT; -}; -template -using ConditionalType = typename Conditional::type; - -} // namespace cpp -} // namespace __llvm_libc - -#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H diff --git a/libc/src/__support/CPP/Utility.h b/libc/src/__support/CPP/Utility.h --- a/libc/src/__support/CPP/Utility.h +++ b/libc/src/__support/CPP/Utility.h @@ -9,12 +9,12 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_H #define LLVM_LIBC_SRC_SUPPORT_CPP_UTILITY_H -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" namespace __llvm_libc::cpp { template struct IntegerSequence { - static_assert(IsIntegral::Value); + static_assert(is_integral_v); template using append = IntegerSequence; }; diff --git a/libc/src/__support/CPP/atomic.h b/libc/src/__support/CPP/atomic.h --- a/libc/src/__support/CPP/atomic.h +++ b/libc/src/__support/CPP/atomic.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_CPP_ATOMIC_H #define LLVM_LIBC_SRC_SUPPORT_CPP_ATOMIC_H -#include "TypeTraits.h" +#include "type_traits.h" namespace __llvm_libc { namespace cpp { @@ -25,7 +25,7 @@ template struct Atomic { // For now, we will restrict to only arithmetic types. - static_assert(IsArithmetic::Value, "Only arithmetic types can be atomic."); + static_assert(is_arithmetic_v, "Only arithmetic types can be atomic."); private: // The value stored should be appropriately aligned so that diff --git a/libc/src/__support/CPP/stringstream.h b/libc/src/__support/CPP/stringstream.h --- a/libc/src/__support/CPP/stringstream.h +++ b/libc/src/__support/CPP/stringstream.h @@ -11,7 +11,7 @@ #include "ArrayRef.h" #include "StringView.h" -#include "TypeTraits.h" +#include "type_traits.h" #include "src/__support/integer_to_string.h" @@ -56,17 +56,17 @@ } // Write the |val| as string. - template ::Value, int> = 0> + template , int> = 0> StringStream &operator<<(T val) { const auto int_to_str = integer_to_string(val); return operator<<(int_to_str.str()); } - template ::Value, int> = 0> + template , int> = 0> StringStream &operator<<(T val) { // If this specialization gets activated, then the static_assert will // trigger a compile error about missing floating point number support. - static_assert(!IsFloatingPointType::Value, + static_assert(!is_floating_point_v, "Writing floating point numbers is not yet supported"); return *this; } diff --git a/libc/src/__support/CPP/type_traits.h b/libc/src/__support/CPP/type_traits.h new file mode 100644 --- /dev/null +++ b/libc/src/__support/CPP/type_traits.h @@ -0,0 +1,173 @@ +//===-- 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. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H +#define LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H + +#include "UInt.h" + +namespace __llvm_libc { +namespace cpp { + +template struct enable_if; +template struct enable_if { + using type = T; +}; +template +using enable_if_t = typename enable_if::type; + +template struct integral_constant { + using value_type = T; + static constexpr T value = v; +}; +using true_type = cpp::integral_constant; +using false_type = cpp::integral_constant; + +template struct type_identity { + using type = T; +}; + +template struct is_same : cpp::false_type {}; +template struct is_same : cpp::true_type {}; +template +inline constexpr bool is_same_v = is_same::value; + +template struct remove_cv : public type_identity {}; +template struct remove_cv : public type_identity {}; +template struct remove_cv : public type_identity {}; +template +struct remove_cv : public type_identity {}; +template using remove_cv_t = typename remove_cv::type; + +template struct is_integral { +private: + using unqualified_type = remove_cv_t; + +public: + static constexpr bool value = + is_same_v || + is_same_v || + is_same_v || + is_same_v || + is_same_v || + is_same_v || + is_same_v || + is_same_v || + is_same_v || + is_same_v || + is_same_v || + is_same_v || + // We need to include UInt<128> and __uint128_t when available because + // we want to unittest UInt<128>. If we include only UInt128, then on + // platform where it resolves to __uint128_t, we cannot unittest + // UInt<128>. + is_same_v<__llvm_libc::cpp::UInt<128>, unqualified_type> +#ifdef __SIZEOF_INT128__ + || is_same_v<__int128_t, unqualified_type> || + is_same_v<__uint128_t, unqualified_type> +#endif + ; +}; +template +inline constexpr bool is_integral_v = is_integral::value; + +template struct is_enum { + static constexpr bool value = __is_enum(T); +}; + +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 inline constexpr bool is_pointer_v = is_pointer::value; + +template struct is_floating_point { +private: + using unqualified_type = remove_cv_t; + +public: + static constexpr bool value = is_same_v || + is_same_v || + is_same_v; +}; +template +inline constexpr bool is_floating_point_v = is_floating_point::value; + +template struct is_arithmetic { + static constexpr bool value = + is_integral::value || is_floating_point::value; +}; +template +inline constexpr bool is_arithmetic_v = is_arithmetic::value; + +template struct is_signed { + static constexpr bool value = is_arithmetic::value && (T(-1) < T(0)); + constexpr operator bool() const { return value; } + constexpr bool operator()() const { return value; } +}; +template inline constexpr bool is_signed_v = is_signed::value; + +template struct make_unsigned; +template <> struct make_unsigned { + using type = unsigned char; +}; +template <> struct make_unsigned { + using type = unsigned char; +}; +template <> struct make_unsigned { + using type = unsigned short; +}; +template <> struct make_unsigned { + using type = unsigned int; +}; +template <> struct make_unsigned { + using type = unsigned long; +}; +template <> struct make_unsigned { + using type = unsigned long long; +}; +template <> struct make_unsigned { + using type = unsigned char; +}; +template <> struct make_unsigned { + using type = unsigned short; +}; +template <> struct make_unsigned { + using type = unsigned int; +}; +template <> struct make_unsigned { + using type = unsigned long; +}; +template <> struct make_unsigned { + using type = unsigned long long; +}; +#ifdef __SIZEOF_INT128__ +template <> struct make_unsigned<__int128_t> { + using type = __uint128_t; +}; +template <> struct make_unsigned<__uint128_t> { + using type = __uint128_t; +}; +#endif +template using make_unsigned_t = typename make_unsigned::type; + +// Compile time type selection. +template struct conditional { + using type = T; +}; +template struct conditional { + using type = F; +}; +template +using conditional_t = typename conditional::type; + +} // namespace cpp +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_SUPPORT_CPP_TYPETRAITS_H diff --git a/libc/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h --- a/libc/src/__support/FPUtil/BasicOperations.h +++ b/libc/src/__support/FPUtil/BasicOperations.h @@ -11,21 +11,19 @@ #include "FPBits.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" namespace __llvm_libc { namespace fputil { -template ::Value, int> = 0> +template , int> = 0> static inline T abs(T x) { FPBits bits(x); bits.set_sign(0); return T(bits); } -template ::Value, int> = 0> +template , int> = 0> static inline T fmin(T x, T y) { FPBits bitx(x), bity(y); @@ -43,8 +41,7 @@ } } -template ::Value, int> = 0> +template , int> = 0> static inline T fmax(T x, T y) { FPBits bitx(x), bity(y); @@ -62,8 +59,7 @@ } } -template ::Value, int> = 0> +template , int> = 0> static inline T fdim(T x, T y) { FPBits bitx(x), bity(y); diff --git a/libc/src/__support/FPUtil/DivisionAndRemainderOperations.h b/libc/src/__support/FPUtil/DivisionAndRemainderOperations.h --- a/libc/src/__support/FPUtil/DivisionAndRemainderOperations.h +++ b/libc/src/__support/FPUtil/DivisionAndRemainderOperations.h @@ -13,7 +13,7 @@ #include "ManipulationFunctions.h" #include "NormalFloat.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" namespace __llvm_libc { namespace fputil { @@ -22,8 +22,7 @@ // The implementation is a bit-by-bit algorithm which uses integer division // to evaluate the quotient and remainder. -template ::Value, int> = 0> +template , int> = 0> static inline T remquo(T x, T y, int &q) { FPBits xbits(x), ybits(y); if (xbits.is_nan()) diff --git a/libc/src/__support/FPUtil/FMA.h b/libc/src/__support/FPUtil/FMA.h --- a/libc/src/__support/FPUtil/FMA.h +++ b/libc/src/__support/FPUtil/FMA.h @@ -22,7 +22,7 @@ #else // FMA instructions are not available #include "generic/FMA.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" namespace __llvm_libc { namespace fputil { diff --git a/libc/src/__support/FPUtil/FPBits.h b/libc/src/__support/FPUtil/FPBits.h --- a/libc/src/__support/FPUtil/FPBits.h +++ b/libc/src/__support/FPUtil/FPBits.h @@ -12,7 +12,7 @@ #include "PlatformDefs.h" #include "src/__support/CPP/Bit.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/builtin_wrappers.h" #include "src/__support/common.h" @@ -39,7 +39,7 @@ // an x87 floating point format. This format is an IEEE 754 extension format. // It is handled as an explicit specialization of this class. template struct FPBits { - static_assert(cpp::IsFloatingPointType::Value, + static_assert(cpp::is_floating_point_v, "FPBits instantiated with invalid type."); // Reinterpreting bits as an integer value and interpreting the bits of an @@ -103,13 +103,12 @@ // We don't want accidental type promotions/conversions, so we require exact // type match. - template ::Value, int> = 0> + template , int> = 0> constexpr explicit FPBits(XType x) : bits(__llvm_libc::bit_cast(x)) {} template ::Value, int> = 0> + cpp::enable_if_t, int> = 0> constexpr explicit FPBits(XType x) : bits(x) {} FPBits() : bits(0) {} diff --git a/libc/src/__support/FPUtil/Hypot.h b/libc/src/__support/FPUtil/Hypot.h --- a/libc/src/__support/FPUtil/Hypot.h +++ b/libc/src/__support/FPUtil/Hypot.h @@ -14,8 +14,8 @@ #include "FPBits.h" #include "builtin_wrappers.h" #include "src/__support/CPP/Bit.h" -#include "src/__support/CPP/TypeTraits.h" #include "src/__support/CPP/UInt128.h" +#include "src/__support/CPP/type_traits.h" namespace __llvm_libc { namespace fputil { @@ -97,8 +97,7 @@ // - HYPOT(x, y) is +Inf if x or y is +Inf or -Inf; else // - HYPOT(x, y) is NaN if x or y is NaN. // -template ::Value, int> = 0> +template , int> = 0> static inline T hypot(T x, T y) { using FPBits_t = FPBits; using UIntType = typename FPBits::UIntType; diff --git a/libc/src/__support/FPUtil/ManipulationFunctions.h b/libc/src/__support/FPUtil/ManipulationFunctions.h --- a/libc/src/__support/FPUtil/ManipulationFunctions.h +++ b/libc/src/__support/FPUtil/ManipulationFunctions.h @@ -15,7 +15,7 @@ #include "PlatformDefs.h" #include "src/__support/CPP/Bit.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include #include @@ -23,8 +23,7 @@ namespace __llvm_libc { namespace fputil { -template ::Value, int> = 0> +template , int> = 0> static inline T frexp(T x, int &exp) { FPBits bits(x); if (bits.is_inf_or_nan()) @@ -40,8 +39,7 @@ return normal; } -template ::Value, int> = 0> +template , int> = 0> static inline T modf(T x, T &iptr) { FPBits bits(x); if (bits.is_zero() || bits.is_nan()) { @@ -62,16 +60,14 @@ } } -template ::Value, int> = 0> +template , int> = 0> static inline T copysign(T x, T y) { FPBits xbits(x); xbits.set_sign(FPBits(y).get_sign()); return T(xbits); } -template ::Value, int> = 0> +template , int> = 0> static inline int ilogb(T x) { // TODO: Raise appropriate floating point exceptions and set errno to the // an appropriate error value wherever relevant. @@ -99,8 +95,7 @@ return normal.exponent; } -template ::Value, int> = 0> +template , int> = 0> static inline T logb(T x) { FPBits bits(x); if (bits.is_zero()) { @@ -118,8 +113,7 @@ return normal.exponent; } -template ::Value, int> = 0> +template , int> = 0> static inline T ldexp(T x, int exp) { FPBits bits(x); if (bits.is_zero() || bits.is_inf_or_nan() || exp == 0) @@ -145,8 +139,7 @@ return normal; } -template ::Value, int> = 0> +template , int> = 0> static inline T nextafter(T from, T to) { FPBits from_bits(from); if (from_bits.is_nan()) diff --git a/libc/src/__support/FPUtil/NearestIntegerOperations.h b/libc/src/__support/FPUtil/NearestIntegerOperations.h --- a/libc/src/__support/FPUtil/NearestIntegerOperations.h +++ b/libc/src/__support/FPUtil/NearestIntegerOperations.h @@ -12,7 +12,7 @@ #include "FEnvImpl.h" #include "FPBits.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include #include @@ -20,8 +20,7 @@ namespace __llvm_libc { namespace fputil { -template ::Value, int> = 0> +template , int> = 0> static inline T trunc(T x) { FPBits bits(x); @@ -52,8 +51,7 @@ return T(bits); } -template ::Value, int> = 0> +template , int> = 0> static inline T ceil(T x) { FPBits bits(x); @@ -91,8 +89,7 @@ return trunc_value + T(1.0); } -template ::Value, int> = 0> +template , int> = 0> static inline T floor(T x) { FPBits bits(x); if (bits.get_sign()) { @@ -102,8 +99,7 @@ } } -template ::Value, int> = 0> +template , int> = 0> static inline T round(T x) { using UIntType = typename FPBits::UIntType; FPBits bits(x); @@ -154,8 +150,7 @@ } } -template ::Value, int> = 0> +template , int> = 0> static inline T round_using_current_rounding_mode(T x) { using UIntType = typename FPBits::UIntType; FPBits bits(x); @@ -235,9 +230,8 @@ namespace internal { template ::Value && - cpp::IsIntegral::Value, - int> = 0> + cpp::enable_if_t && cpp::is_integral_v, + int> = 0> static inline I rounded_float_to_signed_integer(F x) { constexpr I INTEGER_MIN = (I(1) << (sizeof(I) * 8 - 1)); constexpr I INTEGER_MAX = -(INTEGER_MIN + 1); @@ -277,17 +271,15 @@ } // namespace internal template ::Value && - cpp::IsIntegral::Value, - int> = 0> + cpp::enable_if_t && cpp::is_integral_v, + int> = 0> static inline I round_to_signed_integer(F x) { return internal::rounded_float_to_signed_integer(round(x)); } template ::Value && - cpp::IsIntegral::Value, - int> = 0> + cpp::enable_if_t && cpp::is_integral_v, + int> = 0> static inline I round_to_signed_integer_using_current_rounding_mode(F x) { return internal::rounded_float_to_signed_integer( round_using_current_rounding_mode(x)); diff --git a/libc/src/__support/FPUtil/NormalFloat.h b/libc/src/__support/FPUtil/NormalFloat.h --- a/libc/src/__support/FPUtil/NormalFloat.h +++ b/libc/src/__support/FPUtil/NormalFloat.h @@ -11,7 +11,7 @@ #include "FPBits.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include @@ -27,7 +27,7 @@ // where is of the form 1.<...>. template struct NormalFloat { static_assert( - cpp::IsFloatingPointType::Value, + cpp::is_floating_point_v, "NormalFloat template parameter has to be a floating point type."); using UIntType = typename FPBits::UIntType; diff --git a/libc/src/__support/FPUtil/aarch64/FMA.h b/libc/src/__support/FPUtil/aarch64/FMA.h --- a/libc/src/__support/FPUtil/aarch64/FMA.h +++ b/libc/src/__support/FPUtil/aarch64/FMA.h @@ -19,13 +19,13 @@ #error "FMA instructions are not supported" #endif -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" namespace __llvm_libc { namespace fputil { template -cpp::EnableIfType::Value, T> fma(T x, T y, T z) { +cpp::enable_if_t, T> fma(T x, T y, T z) { float result; __asm__ __volatile__("fmadd %s0, %s1, %s2, %s3\n\t" : "=w"(result) @@ -34,7 +34,7 @@ } template -cpp::EnableIfType::Value, T> fma(T x, T y, T z) { +cpp::enable_if_t :, T> fma(T x, T y, T z) { double result; __asm__ __volatile__("fmadd %d0, %d1, %d2, %d3\n\t" : "=w"(result) diff --git a/libc/src/__support/FPUtil/generic/FMA.h b/libc/src/__support/FPUtil/generic/FMA.h --- a/libc/src/__support/FPUtil/generic/FMA.h +++ b/libc/src/__support/FPUtil/generic/FMA.h @@ -10,8 +10,8 @@ #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMA_H #include "src/__support/CPP/Bit.h" -#include "src/__support/CPP/TypeTraits.h" #include "src/__support/CPP/UInt128.h" +#include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/FloatProperties.h" diff --git a/libc/src/__support/FPUtil/generic/FMod.h b/libc/src/__support/FPUtil/generic/FMod.h --- a/libc/src/__support/FPUtil/generic/FMod.h +++ b/libc/src/__support/FPUtil/generic/FMod.h @@ -10,7 +10,7 @@ #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_GENERIC_FMOD_H #include "src/__support/CPP/Limits.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/builtin_wrappers.h" @@ -119,7 +119,7 @@ // https://www.open-std.org/JTC1/SC22/WG14/www/docs/n1011.htm template struct FModExceptionalInputHandler { - static_assert(cpp::IsFloatingPointType::Value, + static_assert(cpp::is_floating_point_v, "FModCStandardWrapper instantiated with invalid type."); static bool PreCheck(T x, T y, T &out) { @@ -157,7 +157,7 @@ template struct FModFastMathWrapper { - static_assert(cpp::IsFloatingPointType::Value, + static_assert(cpp::is_floating_point_v, "FModFastMathWrapper instantiated with invalid type."); static bool PreCheck(T, T, T &) { return false; } @@ -216,7 +216,7 @@ template , class DivisionHelper = FModDivisionSimpleHelper> class FMod { - static_assert(cpp::IsFloatingPointType::Value, + static_assert(cpp::is_floating_point_v, "FMod instantiated with invalid type."); private: diff --git a/libc/src/__support/FPUtil/generic/sqrt.h b/libc/src/__support/FPUtil/generic/sqrt.h --- a/libc/src/__support/FPUtil/generic/sqrt.h +++ b/libc/src/__support/FPUtil/generic/sqrt.h @@ -11,8 +11,8 @@ #include "sqrt_80_bit_long_double.h" #include "src/__support/CPP/Bit.h" -#include "src/__support/CPP/TypeTraits.h" #include "src/__support/CPP/UInt128.h" +#include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/FEnvImpl.h" #include "src/__support/FPUtil/FPBits.h" #include "src/__support/FPUtil/PlatformDefs.h" @@ -64,8 +64,7 @@ // Correctly rounded IEEE 754 SQRT for all rounding modes. // Shift-and-add algorithm. template -static inline cpp::EnableIfType::Value, T> -sqrt(T x) { +static inline cpp::enable_if_t, T> sqrt(T x) { if constexpr (internal::SpecialLongDouble::VALUE) { // Special 80-bit long double. diff --git a/libc/src/__support/FPUtil/x86_64/FMA.h b/libc/src/__support/FPUtil/x86_64/FMA.h --- a/libc/src/__support/FPUtil/x86_64/FMA.h +++ b/libc/src/__support/FPUtil/x86_64/FMA.h @@ -19,15 +19,14 @@ #error "FMA instructions are not supported" #endif -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include namespace __llvm_libc { namespace fputil { template -static inline cpp::EnableIfType::Value, T> fma(T x, T y, - T z) { +static inline cpp::enable_if_t, T> fma(T x, T y, T z) { float result; __m128 xmm = _mm_load_ss(&x); // NOLINT __m128 ymm = _mm_load_ss(&y); // NOLINT @@ -38,8 +37,8 @@ } template -static inline cpp::EnableIfType::Value, T> fma(T x, T y, - T z) { +static inline cpp::enable_if_t, T> fma(T x, T y, + T z) { double result; __m128d xmm = _mm_load_sd(&x); // NOLINT __m128d ymm = _mm_load_sd(&y); // NOLINT diff --git a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h --- a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h +++ b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h @@ -100,7 +100,7 @@ FPBits() : bits(0) {} template ::Value, int> = 0> + cpp::enable_if_t, int> = 0> explicit FPBits(XType x) : bits(__llvm_libc::bit_cast(x)) { // bits starts uninitialized, and setting it to a long double only // overwrites the first 80 bits. This clears those upper bits. @@ -108,7 +108,7 @@ } template ::Value, int> = 0> + cpp::enable_if_t, int> = 0> explicit FPBits(XType x) : bits(x) {} operator long double() { return __llvm_libc::bit_cast(bits); } diff --git a/libc/src/__support/integer_operations.h b/libc/src/__support/integer_operations.h --- a/libc/src/__support/integer_operations.h +++ b/libc/src/__support/integer_operations.h @@ -9,18 +9,17 @@ #ifndef LLVM_LIBC_SRC_STDLIB_ABS_UTILS_H #define LLVM_LIBC_SRC_STDLIB_ABS_UTILS_H -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" namespace __llvm_libc { template -static constexpr cpp::EnableIfType::Value, T> -integer_abs(T n) { +static constexpr cpp::enable_if_t, T> integer_abs(T n) { return (n < 0) ? -n : n; } template -static constexpr cpp::EnableIfType::Value, void> +static constexpr cpp::enable_if_t, void> integer_rem_quo(T x, T y, T ", T &rem) { quot = x / y; rem = x % y; diff --git a/libc/src/__support/integer_to_string.h b/libc/src/__support/integer_to_string.h --- a/libc/src/__support/integer_to_string.h +++ b/libc/src/__support/integer_to_string.h @@ -10,15 +10,15 @@ #define LLVM_LIBC_SRC_SUPPORT_INTEGER_TO_STRING_H #include "src/__support/CPP/StringView.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" namespace __llvm_libc { template class IntegerToString { - static_assert(cpp::IsIntegral::Value, + static_assert(cpp::is_integral_v, "IntegerToString can only be used with integral types."); - using UnsignedType = cpp::MakeUnsignedType; + using UnsignedType = cpp::make_unsigned_t; // We size the string buffer using an approximation algorithm: // @@ -39,7 +39,7 @@ // add an additional byte to accommodate the '-' sign in case of signed // integers. static constexpr size_t BUFSIZE = - (sizeof(T) * 5 + 1) / 2 + (cpp::IsSigned() ? 1 : 0); + (sizeof(T) * 5 + 1) / 2 + (cpp::is_signed() ? 1 : 0); char strbuf[BUFSIZE] = {'\0'}; size_t len = 0; diff --git a/libc/src/math/generic/math_utils.h b/libc/src/math/generic/math_utils.h --- a/libc/src/math/generic/math_utils.h +++ b/libc/src/math/generic/math_utils.h @@ -10,7 +10,7 @@ #define LLVM_LIBC_SRC_MATH_MATH_UTILS_H #include "src/__support/CPP/Bit.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include "src/__support/common.h" #include #include @@ -72,11 +72,11 @@ template struct IsFloatOrDouble { static constexpr bool Value = // NOLINT so that this Value can match the ones for IsSame - cpp::IsSame::Value || cpp::IsSame::Value; + cpp::is_same_v || cpp::is_same_v; }; template -using EnableIfFloatOrDouble = cpp::EnableIfType::Value, int>; +using EnableIfFloatOrDouble = cpp::enable_if_t::Value, int>; template = 0> T xflow(uint32_t sign, T y) { diff --git a/libc/src/string/memory_utils/address.h b/libc/src/string/memory_utils/address.h --- a/libc/src/string/memory_utils/address.h +++ b/libc/src/string/memory_utils/address.h @@ -12,7 +12,7 @@ #ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_COMMON_H #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_COMMON_H -#include "src/__support/CPP/TypeTraits.h" // cpp::ConditionalType +#include "src/__support/CPP/type_traits.h" // cpp::ConditionalType #include "src/string/memory_utils/utils.h" // is_power2 #include // size_t #include // uint8_t, uint16_t, uint32_t, uint64_t @@ -48,8 +48,8 @@ static constexpr Temporality TEMPORALITY = TS; static constexpr bool IS_READ = P == Permission::Read; static constexpr bool IS_WRITE = P == Permission::Write; - using PointeeType = cpp::ConditionalType; - using VoidType = cpp::ConditionalType; + using PointeeType = cpp::conditional_t; + using VoidType = cpp::conditional_t; Address(VoidType *ptr) : ptr_(reinterpret_cast(ptr)) {} @@ -79,15 +79,15 @@ } }; -template struct IsAddressType : public cpp::FalseValue {}; +template struct IsAddressType : public cpp::false_type {}; template -struct IsAddressType> : public cpp::TrueValue {}; +struct IsAddressType> : public cpp::true_type {}; // Reinterpret the address as a pointer to T. // This is not UB since the underlying pointer always refers to a `char` in a // buffer of raw data. template static T *as(AddrT addr) { - static_assert(IsAddressType::Value); + static_assert(IsAddressType::value); return reinterpret_cast(addr.ptr()); } @@ -95,7 +95,7 @@ // alignment whenever possible. template static auto offsetAddr(AddrT addr) { - static_assert(IsAddressType::Value); + static_assert(IsAddressType::value); return addr.template offset(ByteOffset); } @@ -103,7 +103,7 @@ // address will be Alignment aligned. template static auto offsetAddrAssumeAligned(AddrT addr, size_t byte_offset) { - static_assert(IsAddressType::Value); + static_assert(IsAddressType::value); return Address(addr.ptr_ + byte_offset); } @@ -112,7 +112,7 @@ // ByteOffset. This allows to propagate the address alignment whenever possible. template static auto offsetAddrMultiplesOf(AddrT addr, ptrdiff_t byte_offset) { - static_assert(IsAddressType::Value); + static_assert(IsAddressType::value); return addr.template offset(byte_offset); } diff --git a/libc/src/string/memory_utils/algorithm.h b/libc/src/string/memory_utils/algorithm.h --- a/libc/src/string/memory_utils/algorithm.h +++ b/libc/src/string/memory_utils/algorithm.h @@ -71,7 +71,7 @@ // Because of the runtime size, we loose the alignment information. template static auto tailAddr(AddrT addr, size_t runtime_size) { - static_assert(IsAddressType::Value); + static_assert(IsAddressType::value); return offsetAddrAssumeAligned<1>(addr, runtime_size - Size); } @@ -440,8 +440,8 @@ template static auto align(Arg1AddrT arg1, Arg2AddrT arg2, size_t runtime_size) { - static_assert(IsAddressType::Value); - static_assert(IsAddressType::Value); + static_assert(IsAddressType::value); + static_assert(IsAddressType::value); if constexpr (AlignOn == Arg::_1) { auto offset = offset_to_next_aligned(arg1.ptr_); return makeAligned(offsetAddrAssumeAligned(arg1, offset), diff --git a/libc/src/string/memory_utils/backend_aarch64.h b/libc/src/string/memory_utils/backend_aarch64.h --- a/libc/src/string/memory_utils/backend_aarch64.h +++ b/libc/src/string/memory_utils/backend_aarch64.h @@ -22,7 +22,7 @@ static constexpr bool IS_BACKEND_TYPE = true; template , bool> = true> + cpp::enable_if_t, bool> = true> static inline T load(const T *src) { return Scalar64BitBackend::template load(src); } diff --git a/libc/src/string/memory_utils/backend_scalar.h b/libc/src/string/memory_utils/backend_scalar.h --- a/libc/src/string/memory_utils/backend_scalar.h +++ b/libc/src/string/memory_utils/backend_scalar.h @@ -8,7 +8,7 @@ #ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BACKEND_SCALAR_H #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BACKEND_SCALAR_H -#include "src/__support/CPP/TypeTraits.h" // ConditionalType, EnableIfType +#include "src/__support/CPP/type_traits.h" // ConditionalType, enable_if_t #include "src/__support/endian.h" namespace __llvm_libc { @@ -18,8 +18,8 @@ template static constexpr bool IsScalarType = - cpp::IsSameV || cpp::IsSameV || - cpp::IsSameV || cpp::IsSameV; + cpp::is_same_v || cpp::is_same_v || + cpp::is_same_v || cpp::is_same_v; template static inline T load(const T *src) { @@ -53,10 +53,10 @@ // Returns the type to use to consume Size bytes. template - using getNextType = cpp::ConditionalType< + using getNextType = cpp::conditional_t< Size >= 8, uint64_t, - cpp::ConditionalType= 4, uint32_t, - cpp::ConditionalType= 2, uint16_t, uint8_t>>>; + cpp::conditional_t= 4, uint32_t, + cpp::conditional_t= 2, uint16_t, uint8_t>>>; }; template <> diff --git a/libc/src/string/memory_utils/backend_x86.h b/libc/src/string/memory_utils/backend_x86.h --- a/libc/src/string/memory_utils/backend_x86.h +++ b/libc/src/string/memory_utils/backend_x86.h @@ -9,7 +9,7 @@ #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BACKEND_X86_H #if defined(LLVM_LIBC_ARCH_X86) -#include "src/__support/CPP/TypeTraits.h" // ConditionalType, EnableIfType +#include "src/__support/CPP/type_traits.h" // ConditionalType, enable_if_t #include "src/string/memory_utils/backend_scalar.h" #ifdef __SSE2__ @@ -40,63 +40,61 @@ // Scalar types use base class implementations. template , bool> = true> + cpp::enable_if_t, bool> = true> static inline T load(const T *src) { return Scalar64BitBackend::template load(src); } // Scalar types use base class implementations. template , bool> = true> + cpp::enable_if_t, bool> = true> static inline void store(T *dst, T value) { Scalar64BitBackend::template store(dst, value); } // Scalar types use base class implementations. template , bool> = true> + cpp::enable_if_t, bool> = true> static inline uint64_t notEquals(T v1, T v2) { return Scalar64BitBackend::template notEquals(v1, v2); } // Scalar types use base class implementations. template , bool> = true> + cpp::enable_if_t, bool> = true> static inline T splat(ubyte value) { return Scalar64BitBackend::template splat(value); } // Scalar types use base class implementations. template , bool> = true> + cpp::enable_if_t, bool> = true> static inline int32_t threeWayCmp(T v1, T v2) { return Scalar64BitBackend::template threeWayCmp(v1, v2); } // X86 types are specialized below. - template < - typename T, Temporality TS, Aligned AS, - cpp::EnableIfType, bool> = true> + template , bool> = true> static inline T load(const T *src); // X86 types are specialized below. - template < - typename T, Temporality TS, Aligned AS, - cpp::EnableIfType, bool> = true> + template , bool> = true> static inline void store(T *dst, T value); // X86 types are specialized below. - template , - bool> = true> + template , bool> = true> static inline T splat(ubyte value); // X86 types are specialized below. - template , - bool> = true> + template , bool> = true> static inline uint64_t notEquals(T v1, T v2); - template , - bool> = true> + template , bool> = true> static inline int32_t threeWayCmp(T v1, T v2) { return char_diff(reinterpret_cast(&v1), reinterpret_cast(&v2), notEquals(v1, v2)); @@ -104,12 +102,12 @@ // Returns the type to use to consume Size bytes. template - using getNextType = cpp::ConditionalType< + using getNextType = cpp::conditional_t< (HAS_M512 && Size >= 64), __m512i, - cpp::ConditionalType< + cpp::conditional_t< (HAS_M256 && Size >= 32), __m256i, - cpp::ConditionalType<(HAS_M128 && Size >= 16), __m128i, - Scalar64BitBackend::getNextType>>>; + cpp::conditional_t<(HAS_M128 && Size >= 16), __m128i, + Scalar64BitBackend::getNextType>>>; private: static inline int32_t char_diff(const char *a, const char *b, uint64_t mask) { diff --git a/libc/src/string/memory_utils/sized_op.h b/libc/src/string/memory_utils/sized_op.h --- a/libc/src/string/memory_utils/sized_op.h +++ b/libc/src/string/memory_utils/sized_op.h @@ -50,7 +50,7 @@ // This is possible because the address type carries known compile-time // alignment informations. template static constexpr Aligned isAligned() { - static_assert(IsAddressType::Value); + static_assert(IsAddressType::value); return AddrT::ALIGNMENT > 1 && AddrT::ALIGNMENT >= sizeof(T) ? Aligned::YES : Aligned::NO; } @@ -59,7 +59,7 @@ // This function is responsible for extracting Temporality and Alignment from // the Address type. template static inline auto nativeLoad(SrcAddrT src) { - static_assert(IsAddressType::Value && SrcAddrT::IS_READ); + static_assert(IsAddressType::value && SrcAddrT::IS_READ); constexpr auto AS = isAligned(); constexpr auto TS = SrcAddrT::TEMPORALITY; return Backend::template load(as(src)); @@ -70,7 +70,7 @@ // the Address type. template static inline void nativeStore(type value, DstAddrT dst) { - static_assert(IsAddressType::Value && DstAddrT::IS_WRITE); + static_assert(IsAddressType::value && DstAddrT::IS_WRITE); constexpr auto AS = isAligned(); constexpr auto TS = DstAddrT::TEMPORALITY; return Backend::template store(as(dst), value); @@ -85,8 +85,8 @@ public: template static inline void copy(DstAddrT dst, SrcAddrT src) { - static_assert(IsAddressType::Value && DstAddrT::IS_WRITE); - static_assert(IsAddressType::Value && SrcAddrT::IS_READ); + static_assert(IsAddressType::value && DstAddrT::IS_WRITE); + static_assert(IsAddressType::value && SrcAddrT::IS_READ); if constexpr (LLVM_LIBC_USE_BUILTIN_MEMCPY_INLINE && DstAddrT::TEMPORALITY == Temporality::TEMPORAL && SrcAddrT::TEMPORALITY == Temporality::TEMPORAL) { diff --git a/libc/test/src/__support/CPP/integer_sequence_test.cpp b/libc/test/src/__support/CPP/integer_sequence_test.cpp --- a/libc/test/src/__support/CPP/integer_sequence_test.cpp +++ b/libc/test/src/__support/CPP/integer_sequence_test.cpp @@ -12,13 +12,13 @@ using namespace __llvm_libc::cpp; TEST(LlvmLibcIntegerSequencetTest, Basic) { - EXPECT_TRUE((IsSameV, MakeIntegerSequence>)); + EXPECT_TRUE((is_same_v, MakeIntegerSequence>)); using ISeq = IntegerSequence; - EXPECT_TRUE((IsSameV>)); + EXPECT_TRUE((is_same_v>)); using LSeq = IntegerSequence; - EXPECT_TRUE((IsSameV>)); + EXPECT_TRUE((is_same_v>)); using ULLSeq = IntegerSequence; - EXPECT_TRUE((IsSameV>)); + EXPECT_TRUE((is_same_v>)); } template diff --git a/libc/test/src/math/NextAfterTest.h b/libc/test/src/math/NextAfterTest.h --- a/libc/test/src/math/NextAfterTest.h +++ b/libc/test/src/math/NextAfterTest.h @@ -10,7 +10,7 @@ #define LLVM_LIBC_TEST_SRC_MATH_NEXTAFTERTEST_H #include "src/__support/CPP/Bit.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/BasicOperations.h" #include "src/__support/FPUtil/FPBits.h" #include "utils/UnitTest/FPMatcher.h" diff --git a/libc/test/src/math/exhaustive/exhaustive_test.h b/libc/test/src/math/exhaustive/exhaustive_test.h --- a/libc/test/src/math/exhaustive/exhaustive_test.h +++ b/libc/test/src/math/exhaustive/exhaustive_test.h @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/FPBits.h" #include "utils/MPFRWrapper/MPFRUtils.h" #include "utils/UnitTest/Test.h" @@ -21,7 +21,7 @@ struct LlvmLibcExhaustiveTest : public __llvm_libc::testing::Test { static constexpr T increment = (1 << 20); static_assert( - __llvm_libc::cpp::IsSameV< + __llvm_libc::cpp::is_same_v< T, typename __llvm_libc::fputil::FPBits::UIntType>, "Types are not consistent"); // Break [start, stop) into `nthreads` subintervals and apply *check to each diff --git a/libc/test/src/math/exhaustive/fmod_generic_impl_test.cpp b/libc/test/src/math/exhaustive/fmod_generic_impl_test.cpp --- a/libc/test/src/math/exhaustive/fmod_generic_impl_test.cpp +++ b/libc/test/src/math/exhaustive/fmod_generic_impl_test.cpp @@ -5,7 +5,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include "src/__support/FPUtil/generic/FMod.h" #include "utils/MPFRWrapper/MPFRUtils.h" #include "utils/UnitTest/FPMatcher.h" @@ -19,7 +19,7 @@ template class LlvmLibcFModTest : public __llvm_libc::testing::Test { - using DivisionHelper = __llvm_libc::cpp::ConditionalType< + using DivisionHelper = __llvm_libc::cpp::conditional_t< InverseMultiplication, __llvm_libc::fputil::generic::FModDivisionInvMultHelper, __llvm_libc::fputil::generic::FModDivisionSimpleHelper>; diff --git a/libc/test/src/string/memory_utils/address_test.cpp b/libc/test/src/string/memory_utils/address_test.cpp --- a/libc/test/src/string/memory_utils/address_test.cpp +++ b/libc/test/src/string/memory_utils/address_test.cpp @@ -4,10 +4,10 @@ namespace __llvm_libc { TEST(LlvmLibcAddress, AliasAreAddresses) { - ASSERT_TRUE(IsAddressType>::Value); - ASSERT_TRUE(IsAddressType>::Value); - ASSERT_TRUE(IsAddressType>::Value); - ASSERT_TRUE(IsAddressType>::Value); + ASSERT_TRUE(IsAddressType>::value); + ASSERT_TRUE(IsAddressType>::value); + ASSERT_TRUE(IsAddressType>::value); + ASSERT_TRUE(IsAddressType>::value); } TEST(LlvmLibcAddress, AliasHaveRightPermissions) { diff --git a/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp b/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp --- a/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp +++ b/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp @@ -73,7 +73,7 @@ if (llvm::StringRef(returnType).contains("_Noreturn")) returnType = "void"; - OS << " static_assert(__llvm_libc::cpp::IsSame<" << returnType << '('; + OS << " static_assert(__llvm_libc::cpp::is_same_v<" << returnType << '('; auto args = functionSpec->getValueAsListOfDefs("Args"); for (size_t i = 0, size = args.size(); i < size; ++i) { llvm::Record *argType = args[i]->getValueAsDef("ArgType"); diff --git a/libc/utils/MPFRWrapper/MPFRUtils.h b/libc/utils/MPFRWrapper/MPFRUtils.h --- a/libc/utils/MPFRWrapper/MPFRUtils.h +++ b/libc/utils/MPFRWrapper/MPFRUtils.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H #define LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include "utils/UnitTest/Test.h" #include "utils/testutils/RoundingModeUtils.h" @@ -81,7 +81,7 @@ template struct BinaryInput { static_assert( - __llvm_libc::cpp::IsFloatingPointType::Value, + __llvm_libc::cpp::is_floating_point_v, "Template parameter of BinaryInput must be a floating point type."); using Type = T; @@ -90,7 +90,7 @@ template struct TernaryInput { static_assert( - __llvm_libc::cpp::IsFloatingPointType::Value, + __llvm_libc::cpp::is_floating_point_v, "Template parameter of TernaryInput must be a floating point type."); using Type = T; @@ -111,7 +111,7 @@ template struct AreMatchingBinaryInputAndBinaryOutput, BinaryOutput> { - static constexpr bool VALUE = cpp::IsFloatingPointType::Value; + static constexpr bool VALUE = cpp::is_floating_point_v; }; template @@ -260,30 +260,30 @@ constexpr bool is_valid_operation() { return (Operation::BeginUnaryOperationsSingleOutput < op && op < Operation::EndUnaryOperationsSingleOutput && - cpp::IsSame::Value && - cpp::IsFloatingPointType::Value) || + cpp::is_same_v && + cpp::is_floating_point_v) || (Operation::BeginUnaryOperationsTwoOutputs < op && op < Operation::EndUnaryOperationsTwoOutputs && - cpp::IsFloatingPointType::Value && - cpp::IsSame>::Value) || + cpp::is_floating_point_v && + cpp::is_same_v>) || (Operation::BeginBinaryOperationsSingleOutput < op && op < Operation::EndBinaryOperationsSingleOutput && - cpp::IsFloatingPointType::Value && - cpp::IsSame>::Value) || + cpp::is_floating_point_v && + cpp::is_same_v>) || (Operation::BeginBinaryOperationsTwoOutputs < op && op < Operation::EndBinaryOperationsTwoOutputs && internal::AreMatchingBinaryInputAndBinaryOutput::VALUE) || (Operation::BeginTernaryOperationsSingleOuput < op && op < Operation::EndTernaryOperationsSingleOutput && - cpp::IsFloatingPointType::Value && - cpp::IsSame>::Value); + cpp::is_floating_point_v && + cpp::is_same_v>); } template __attribute__((no_sanitize("address"))) -cpp::EnableIfType(), - internal::MPFRMatcher> +cpp::enable_if_t(), + internal::MPFRMatcher> get_mpfr_matcher(InputType input, OutputType output_unused, double ulp_tolerance, RoundingMode rounding) { return internal::MPFRMatcher(input, ulp_tolerance, diff --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp --- a/libc/utils/MPFRWrapper/MPFRUtils.cpp +++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp @@ -121,7 +121,7 @@ // conversions. Implicit conversions can potentially lead to loss of // precision. template ::Value, int> = 0> + cpp::enable_if_t, int> = 0> explicit MPFRNumber(XType x, int precision = ExtraPrecision::VALUE, RoundingMode rounding = RoundingMode::Nearest) : mpfr_precision(precision), @@ -131,7 +131,7 @@ } template ::Value, int> = 0> + cpp::enable_if_t, int> = 0> explicit MPFRNumber(XType x, int precision = ExtraPrecision::VALUE, RoundingMode rounding = RoundingMode::Nearest) : mpfr_precision(precision), @@ -141,7 +141,7 @@ } template ::Value, int> = 0> + cpp::enable_if_t, int> = 0> explicit MPFRNumber(XType x, int precision = ExtraPrecision::VALUE, RoundingMode rounding = RoundingMode::Nearest) : mpfr_precision(precision), @@ -151,7 +151,7 @@ } template ::Value, int> = 0> + cpp::enable_if_t, int> = 0> explicit MPFRNumber(XType x, int precision = ExtraPrecision::VALUE, RoundingMode rounding = RoundingMode::Nearest) : mpfr_precision(precision), @@ -396,7 +396,7 @@ // of N between this number and [input]. // 4. A values of +0.0 and -0.0 are treated as equal. template - cpp::EnableIfType::Value, double> ulp(T input) { + cpp::enable_if_t, double> ulp(T input) { T thisAsT = as(); if (thisAsT == input) return T(0.0); @@ -470,7 +470,7 @@ namespace internal { template -cpp::EnableIfType::Value, MPFRNumber> +cpp::enable_if_t, MPFRNumber> unary_operation(Operation op, InputType input, unsigned int precision, RoundingMode rounding) { MPFRNumber mpfrInput(input, precision, rounding); @@ -519,7 +519,7 @@ } template -cpp::EnableIfType::Value, MPFRNumber> +cpp::enable_if_t, MPFRNumber> unary_operation_two_outputs(Operation op, InputType input, int &output, unsigned int precision, RoundingMode rounding) { MPFRNumber mpfrInput(input, precision, rounding); @@ -532,7 +532,7 @@ } template -cpp::EnableIfType::Value, MPFRNumber> +cpp::enable_if_t, MPFRNumber> binary_operation_one_output(Operation op, InputType x, InputType y, unsigned int precision, RoundingMode rounding) { MPFRNumber inputX(x, precision, rounding); @@ -548,7 +548,7 @@ } template -cpp::EnableIfType::Value, MPFRNumber> +cpp::enable_if_t, MPFRNumber> binary_operation_two_outputs(Operation op, InputType x, InputType y, int &output, unsigned int precision, RoundingMode rounding) { @@ -563,7 +563,7 @@ } template -cpp::EnableIfType::Value, MPFRNumber> +cpp::enable_if_t, MPFRNumber> ternary_operation_one_output(Operation op, InputType x, InputType y, InputType z, unsigned int precision, RoundingMode rounding) { diff --git a/libc/utils/UnitTest/FPMatcher.h b/libc/utils/UnitTest/FPMatcher.h --- a/libc/utils/UnitTest/FPMatcher.h +++ b/libc/utils/UnitTest/FPMatcher.h @@ -21,12 +21,12 @@ namespace testing { template -cpp::EnableIfType::Value, void> +cpp::enable_if_t, void> describeValue(const char *label, ValType value, StreamType &stream); template class FPMatcher : public __llvm_libc::testing::Matcher { - static_assert(__llvm_libc::cpp::IsFloatingPointType::Value, + static_assert(__llvm_libc::cpp::is_floating_point_v, "FPMatcher can only be used with floating point values."); static_assert(Condition == __llvm_libc::testing::Cond_EQ || Condition == __llvm_libc::testing::Cond_NE, diff --git a/libc/utils/UnitTest/FPMatcher.cpp b/libc/utils/UnitTest/FPMatcher.cpp --- a/libc/utils/UnitTest/FPMatcher.cpp +++ b/libc/utils/UnitTest/FPMatcher.cpp @@ -20,7 +20,7 @@ namespace testing { template -cpp::EnableIfType::Value, void> +cpp::enable_if_t, void> describeValue(const char *label, ValType value, StreamType &stream) { stream << label; diff --git a/libc/utils/UnitTest/LibcTest.h b/libc/utils/UnitTest/LibcTest.h --- a/libc/utils/UnitTest/LibcTest.h +++ b/libc/utils/UnitTest/LibcTest.h @@ -14,7 +14,7 @@ #include "PlatformDefs.h" -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include "utils/testutils/ExecuteFunction.h" #include "utils/testutils/StreamWrapper.h" @@ -83,23 +83,22 @@ // |Cond| on mismatched |LHS| and |RHS| types can potentially succeed because // of type promotion. template ::Value, int> = 0> + cpp::enable_if_t, int> = 0> bool test(TestCondition Cond, ValType LHS, ValType RHS, const char *LHSStr, const char *RHSStr, const char *File, unsigned long Line) { return internal::test(Ctx, Cond, LHS, RHS, LHSStr, RHSStr, File, Line); } template ::Value, int> = 0> + cpp::enable_if_t::value, int> = 0> bool test(TestCondition Cond, ValType LHS, ValType RHS, const char *LHSStr, const char *RHSStr, const char *File, unsigned long Line) { return internal::test(Ctx, Cond, (long long)LHS, (long long)RHS, LHSStr, RHSStr, File, Line); } - template < - typename ValType, - cpp::EnableIfType::Value, ValType> = nullptr> + template , ValType> = nullptr> bool test(TestCondition Cond, ValType LHS, ValType RHS, const char *LHSStr, const char *RHSStr, const char *File, unsigned long Line) { return internal::test(Ctx, Cond, (unsigned long long)LHS, diff --git a/libc/utils/UnitTest/LibcTest.cpp b/libc/utils/UnitTest/LibcTest.cpp --- a/libc/utils/UnitTest/LibcTest.cpp +++ b/libc/utils/UnitTest/LibcTest.cpp @@ -36,7 +36,7 @@ // When the value is of integral type, just display it as normal. template -cpp::EnableIfType::Value, std::string> +cpp::enable_if_t, std::string> describeValue(ValType Value) { return std::to_string(Value); } diff --git a/libc/utils/UnitTest/StringUtils.h b/libc/utils/UnitTest/StringUtils.h --- a/libc/utils/UnitTest/StringUtils.h +++ b/libc/utils/UnitTest/StringUtils.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_UTILS_UNITTEST_SIMPLE_STRING_CONV_H #define LLVM_LIBC_UTILS_UNITTEST_SIMPLE_STRING_CONV_H -#include "src/__support/CPP/TypeTraits.h" +#include "src/__support/CPP/type_traits.h" #include @@ -17,7 +17,7 @@ // Return the first N hex digits of an integer as a string in upper case. template -cpp::EnableIfType::Value, std::string> +cpp::enable_if_t, std::string> int_to_hex(T X, size_t Length = sizeof(T) * 2) { std::string s(Length, '0'); diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -100,7 +100,7 @@ cc_library( name = "__support_cpp_type_traits", hdrs = [ - "src/__support/CPP/TypeTraits.h", + "src/__support/CPP/type_traits.h", ], deps = [":libc_root","__support_cpp_uint"], )