[libc-commits] [libc] 7738c03 - [libc][NFC] Use RemoveCVType to implement IsIntegral and IsPointerType.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Fri Jul 17 11:42:49 PDT 2020


Author: Siva Chandra Reddy
Date: 2020-07-17T11:32:50-07:00
New Revision: 7738c0341829bdc49d0ad4e9694bdd64aa332023

URL: https://github.com/llvm/llvm-project/commit/7738c0341829bdc49d0ad4e9694bdd64aa332023
DIFF: https://github.com/llvm/llvm-project/commit/7738c0341829bdc49d0ad4e9694bdd64aa332023.diff

LOG: [libc][NFC] Use RemoveCVType to implement IsIntegral and IsPointerType.

Added IsSameV as a convenience variable and used it where convenient.

Reviewers: abrachet, lntue

Differential Revision: https://reviews.llvm.org/D83980

Added: 
    

Modified: 
    libc/utils/CPP/TypeTraits.h

Removed: 
    


################################################################################
diff  --git a/libc/utils/CPP/TypeTraits.h b/libc/utils/CPP/TypeTraits.h
index dfc16b00ab74..9b121c03f8b9 100644
--- a/libc/utils/CPP/TypeTraits.h
+++ b/libc/utils/CPP/TypeTraits.h
@@ -26,27 +26,12 @@ struct FalseValue {
   static constexpr bool Value = false;
 };
 
-template <typename Type> struct IsIntegral : public FalseValue {};
-template <> struct IsIntegral<char> : public TrueValue {};
-template <> struct IsIntegral<signed char> : public TrueValue {};
-template <> struct IsIntegral<unsigned char> : public TrueValue {};
-template <> struct IsIntegral<short> : public TrueValue {};
-template <> struct IsIntegral<unsigned short> : public TrueValue {};
-template <> struct IsIntegral<int> : public TrueValue {};
-template <> struct IsIntegral<unsigned int> : public TrueValue {};
-template <> struct IsIntegral<long> : public TrueValue {};
-template <> struct IsIntegral<unsigned long> : public TrueValue {};
-template <> struct IsIntegral<long long> : public TrueValue {};
-template <> struct IsIntegral<unsigned long long> : public TrueValue {};
-template <> struct IsIntegral<bool> : public TrueValue {};
-
-template <typename T> struct IsPointerType : public FalseValue {};
-template <typename T> struct IsPointerType<T *> : public TrueValue {};
+template <typename T> struct TypeIdentity { typedef T Type; };
 
 template <typename T1, typename T2> struct IsSame : public FalseValue {};
 template <typename T> struct IsSame<T, T> : public TrueValue {};
-
-template <typename T> struct TypeIdentity { typedef T Type; };
+template <typename T1, typename T2>
+static constexpr bool IsSameV = IsSame<T1, T2>::Value;
 
 template <typename T> struct RemoveCV : public TypeIdentity<T> {};
 template <typename T> struct RemoveCV<const T> : public TypeIdentity<T> {};
@@ -56,10 +41,28 @@ struct RemoveCV<const volatile T> : public TypeIdentity<T> {};
 
 template <typename T> using RemoveCVType = typename RemoveCV<T>::Type;
 
+template <typename Type> struct IsIntegral {
+  using TypeNoCV = RemoveCVType<Type>;
+  static constexpr bool Value =
+      IsSameV<char, TypeNoCV> || IsSameV<signed char, TypeNoCV> ||
+      IsSameV<unsigned char, TypeNoCV> || IsSameV<short, TypeNoCV> ||
+      IsSameV<unsigned short, TypeNoCV> || IsSameV<int, TypeNoCV> ||
+      IsSameV<unsigned int, TypeNoCV> || IsSameV<long, TypeNoCV> ||
+      IsSameV<unsigned long, TypeNoCV> || IsSameV<long long, TypeNoCV> ||
+      IsSameV<unsigned long long, TypeNoCV> || IsSameV<bool, TypeNoCV>;
+};
+
+template <typename T> struct IsPointerTypeNoCV : public FalseValue {};
+template <typename T> struct IsPointerTypeNoCV<T *> : public TrueValue {};
+template <typename T> struct IsPointerType {
+  static constexpr bool Value = IsPointerTypeNoCV<RemoveCVType<T>>::Value;
+};
+
 template <typename Type> struct IsFloatingPointType {
-  static constexpr bool Value = IsSame<float, RemoveCVType<Type>>::Value ||
-                                IsSame<double, RemoveCVType<Type>>::Value ||
-                                IsSame<long double, RemoveCVType<Type>>::Value;
+  using TypeNoCV = RemoveCVType<Type>;
+  static constexpr bool Value = IsSame<float, TypeNoCV>::Value ||
+                                IsSame<double, TypeNoCV>::Value ||
+                                IsSame<long double, TypeNoCV>::Value;
 };
 
 } // namespace cpp


        


More information about the libc-commits mailing list