Skip to content

Commit 7738c03

Browse files
author
Siva Chandra Reddy
committed
[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
1 parent 5d06e8b commit 7738c03

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

libc/utils/CPP/TypeTraits.h

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,12 @@ struct FalseValue {
2626
static constexpr bool Value = false;
2727
};
2828

29-
template <typename Type> struct IsIntegral : public FalseValue {};
30-
template <> struct IsIntegral<char> : public TrueValue {};
31-
template <> struct IsIntegral<signed char> : public TrueValue {};
32-
template <> struct IsIntegral<unsigned char> : public TrueValue {};
33-
template <> struct IsIntegral<short> : public TrueValue {};
34-
template <> struct IsIntegral<unsigned short> : public TrueValue {};
35-
template <> struct IsIntegral<int> : public TrueValue {};
36-
template <> struct IsIntegral<unsigned int> : public TrueValue {};
37-
template <> struct IsIntegral<long> : public TrueValue {};
38-
template <> struct IsIntegral<unsigned long> : public TrueValue {};
39-
template <> struct IsIntegral<long long> : public TrueValue {};
40-
template <> struct IsIntegral<unsigned long long> : public TrueValue {};
41-
template <> struct IsIntegral<bool> : public TrueValue {};
42-
43-
template <typename T> struct IsPointerType : public FalseValue {};
44-
template <typename T> struct IsPointerType<T *> : public TrueValue {};
29+
template <typename T> struct TypeIdentity { typedef T Type; };
4530

4631
template <typename T1, typename T2> struct IsSame : public FalseValue {};
4732
template <typename T> struct IsSame<T, T> : public TrueValue {};
48-
49-
template <typename T> struct TypeIdentity { typedef T Type; };
33+
template <typename T1, typename T2>
34+
static constexpr bool IsSameV = IsSame<T1, T2>::Value;
5035

5136
template <typename T> struct RemoveCV : public TypeIdentity<T> {};
5237
template <typename T> struct RemoveCV<const T> : public TypeIdentity<T> {};
@@ -56,10 +41,28 @@ struct RemoveCV<const volatile T> : public TypeIdentity<T> {};
5641

5742
template <typename T> using RemoveCVType = typename RemoveCV<T>::Type;
5843

44+
template <typename Type> struct IsIntegral {
45+
using TypeNoCV = RemoveCVType<Type>;
46+
static constexpr bool Value =
47+
IsSameV<char, TypeNoCV> || IsSameV<signed char, TypeNoCV> ||
48+
IsSameV<unsigned char, TypeNoCV> || IsSameV<short, TypeNoCV> ||
49+
IsSameV<unsigned short, TypeNoCV> || IsSameV<int, TypeNoCV> ||
50+
IsSameV<unsigned int, TypeNoCV> || IsSameV<long, TypeNoCV> ||
51+
IsSameV<unsigned long, TypeNoCV> || IsSameV<long long, TypeNoCV> ||
52+
IsSameV<unsigned long long, TypeNoCV> || IsSameV<bool, TypeNoCV>;
53+
};
54+
55+
template <typename T> struct IsPointerTypeNoCV : public FalseValue {};
56+
template <typename T> struct IsPointerTypeNoCV<T *> : public TrueValue {};
57+
template <typename T> struct IsPointerType {
58+
static constexpr bool Value = IsPointerTypeNoCV<RemoveCVType<T>>::Value;
59+
};
60+
5961
template <typename Type> struct IsFloatingPointType {
60-
static constexpr bool Value = IsSame<float, RemoveCVType<Type>>::Value ||
61-
IsSame<double, RemoveCVType<Type>>::Value ||
62-
IsSame<long double, RemoveCVType<Type>>::Value;
62+
using TypeNoCV = RemoveCVType<Type>;
63+
static constexpr bool Value = IsSame<float, TypeNoCV>::Value ||
64+
IsSame<double, TypeNoCV>::Value ||
65+
IsSame<long double, TypeNoCV>::Value;
6366
};
6467

6568
} // namespace cpp

0 commit comments

Comments
 (0)