|
11 | 11 | #include "include/llvm-libc-macros/stdfix-macros.h" |
12 | 12 | #include "src/__support/CPP/type_traits/bool_constant.h" |
13 | 13 | #include "src/__support/CPP/type_traits/is_arithmetic.h" |
14 | | -#include "src/__support/CPP/type_traits/is_fixed_point.h" |
| 14 | +#include "src/__support/CPP/type_traits/is_same.h" |
| 15 | +#include "src/__support/CPP/type_traits/remove_cv.h" |
15 | 16 | #include "src/__support/macros/attributes.h" |
16 | 17 | #include "src/__support/macros/config.h" |
17 | 18 |
|
18 | 19 | namespace LIBC_NAMESPACE_DECL { |
19 | 20 | namespace cpp { |
20 | 21 |
|
21 | | -// Primary template: handles arithmetic and signed fixed-point types |
| 22 | +#ifndef LIBC_COMPILER_HAS_FIXED_POINT |
22 | 23 | template <typename T> |
23 | 24 | struct is_unsigned : bool_constant<(is_arithmetic_v<T> && (T(-1) > T(0)))> { |
24 | 25 | LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; } |
25 | 26 | LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; } |
26 | 27 | }; |
27 | | - |
28 | | -#ifdef LIBC_COMPILER_HAS_FIXED_POINT |
29 | | -// Specializations for unsigned fixed-point types |
30 | | -template <typename T, bool IsUnsigned> |
31 | | -struct fixed_point_is_unsigned : bool_constant<IsUnsigned> { |
32 | | - LIBC_INLINE constexpr operator bool() const { |
33 | | - return fixed_point_is_unsigned::value; |
34 | | - } |
35 | | - LIBC_INLINE constexpr bool operator()() const { |
36 | | - return fixed_point_is_unsigned::value; |
| 28 | +#else |
| 29 | +template <typename T> struct is_unsigned { |
| 30 | +private: |
| 31 | + template <typename Head, typename... Args> |
| 32 | + LIBC_INLINE static constexpr bool __is_unqualified_any_of() { |
| 33 | + return (... || is_same_v<remove_cv_t<Head>, Args>); |
37 | 34 | } |
| 35 | + |
| 36 | +public: |
| 37 | + LIBC_INLINE_VAR static constexpr bool value = |
| 38 | + (is_arithmetic_v<T> && (T(-1) > T(0))) || |
| 39 | + __is_unqualified_any_of<T, unsigned short fract, unsigned fract, |
| 40 | + unsigned long fract, unsigned short accum, |
| 41 | + unsigned accum, unsigned long accum, |
| 42 | + unsigned short sat fract, unsigned sat fract, |
| 43 | + unsigned long sat fract, unsigned short sat accum, |
| 44 | + unsigned sat accum, unsigned long sat accum>(); |
| 45 | + LIBC_INLINE constexpr operator bool() const { return is_unsigned::value; } |
| 46 | + LIBC_INLINE constexpr bool operator()() const { return is_unsigned::value; } |
38 | 47 | }; |
39 | | -template <> |
40 | | -struct is_unsigned<fract> : fixed_point_is_unsigned<fract, false> {}; |
41 | | -template <> |
42 | | -struct is_unsigned<unsigned short fract> |
43 | | - : fixed_point_is_unsigned<unsigned short fract, true> {}; |
44 | | -template <> |
45 | | -struct is_unsigned<unsigned fract> |
46 | | - : fixed_point_is_unsigned<unsigned fract, true> {}; |
47 | | -template <> |
48 | | -struct is_unsigned<unsigned long fract> |
49 | | - : fixed_point_is_unsigned<unsigned long fract, true> {}; |
50 | | -template <> |
51 | | -struct is_unsigned<short fract> : fixed_point_is_unsigned<short fract, false> { |
52 | | -}; |
53 | | -template <> |
54 | | -struct is_unsigned<long fract> : fixed_point_is_unsigned<long fract, false> {}; |
55 | | -template <> |
56 | | -struct is_unsigned<accum> : fixed_point_is_unsigned<accum, false> {}; |
57 | | -template <> |
58 | | -struct is_unsigned<unsigned short accum> |
59 | | - : fixed_point_is_unsigned<unsigned short accum, true> {}; |
60 | | -template <> |
61 | | -struct is_unsigned<unsigned accum> |
62 | | - : fixed_point_is_unsigned<unsigned accum, true> {}; |
63 | | -template <> |
64 | | -struct is_unsigned<unsigned long accum> |
65 | | - : fixed_point_is_unsigned<unsigned long accum, true> {}; |
66 | | -template <> |
67 | | -struct is_unsigned<short accum> : fixed_point_is_unsigned<short accum, false> { |
68 | | -}; |
69 | | -template <> |
70 | | -struct is_unsigned<long accum> : fixed_point_is_unsigned<long accum, false> {}; |
71 | | -template <> |
72 | | -struct is_unsigned<sat fract> : fixed_point_is_unsigned<sat fract, false> {}; |
73 | | -template <> |
74 | | -struct is_unsigned<unsigned short sat fract> |
75 | | - : fixed_point_is_unsigned<unsigned short sat fract, true> {}; |
76 | | -template <> |
77 | | -struct is_unsigned<unsigned sat fract> |
78 | | - : fixed_point_is_unsigned<unsigned sat fract, true> {}; |
79 | | -template <> |
80 | | -struct is_unsigned<unsigned long sat fract> |
81 | | - : fixed_point_is_unsigned<unsigned long sat fract, true> {}; |
82 | | -template <> |
83 | | -struct is_unsigned<short sat fract> |
84 | | - : fixed_point_is_unsigned<short sat fract, false> {}; |
85 | | -template <> |
86 | | -struct is_unsigned<long sat fract> |
87 | | - : fixed_point_is_unsigned<long sat fract, false> {}; |
88 | | -template <> |
89 | | -struct is_unsigned<sat accum> : fixed_point_is_unsigned<sat accum, false> {}; |
90 | | -template <> |
91 | | -struct is_unsigned<unsigned short sat accum> |
92 | | - : fixed_point_is_unsigned<unsigned short sat accum, true> {}; |
93 | | -template <> |
94 | | -struct is_unsigned<unsigned sat accum> |
95 | | - : fixed_point_is_unsigned<unsigned sat accum, true> {}; |
96 | | -template <> |
97 | | -struct is_unsigned<unsigned long sat accum> |
98 | | - : fixed_point_is_unsigned<unsigned long sat accum, true> {}; |
99 | | -template <> |
100 | | -struct is_unsigned<short sat accum> |
101 | | - : fixed_point_is_unsigned<short sat accum, false> {}; |
102 | | -template <> |
103 | | -struct is_unsigned<long sat accum> |
104 | | - : fixed_point_is_unsigned<long sat accum, false> {}; |
105 | 48 | #endif // LIBC_COMPILER_HAS_FIXED_POINT |
106 | 49 |
|
107 | 50 | template <typename T> |
|
0 commit comments