diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2021-11-02 00:26:46 -0600 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2021-11-02 00:26:46 -0600 |
commit | 943921cf0caefa564601f7b18eed2168be77cfda (patch) | |
tree | cdfbb5a559b7684bc724b6650003204a6e42a02c | |
parent | 6d555ce82e50bdd54896a89d9d547493b466b116 (diff) | |
download | harfbuzz_ng-943921cf0caefa564601f7b18eed2168be77cfda.tar.gz |
[meta] Use more std type_traits
-rw-r--r-- | src/hb-algs.hh | 6 | ||||
-rw-r--r-- | src/hb-map.hh | 8 | ||||
-rw-r--r-- | src/hb-meta.hh | 44 | ||||
-rw-r--r-- | src/hb-open-type.hh | 4 | ||||
-rw-r--r-- | src/hb-serialize.hh | 2 | ||||
-rw-r--r-- | src/test-meta.cc | 3 |
6 files changed, 10 insertions, 57 deletions
diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 55c92841f..446d87e28 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -128,7 +128,7 @@ struct BEInt<Type, 2> template <typename Type> struct BEInt<Type, 3> { - static_assert (!hb_is_signed (Type), ""); + static_assert (!std::is_signed<Type>::value, ""); public: BEInt () = default; constexpr BEInt (Type V) : v {uint8_t ((V >> 16) & 0xFF), @@ -218,7 +218,7 @@ struct impl (const T& v, hb_priority<1>) const HB_RETURN (uint32_t, hb_deref (v).hash ()) template <typename T, - hb_enable_if (hb_is_integral (T))> constexpr auto + hb_enable_if (std::is_integral<T>::value)> constexpr auto impl (const T& v, hb_priority<0>) const HB_AUTO_RETURN ( /* Knuth's multiplicative method: */ @@ -808,7 +808,7 @@ hb_ceil_to_4 (unsigned int v) template <typename T> static inline bool hb_in_range (T u, T lo, T hi) { - static_assert (!hb_is_signed<T>::value, ""); + static_assert (!std::is_signed<T>::value, ""); /* The casts below are important as if T is smaller than int, * the subtract results will become a signed int! */ diff --git a/src/hb-map.hh b/src/hb-map.hh index c14a52af0..790457f26 100644 --- a/src/hb-map.hh +++ b/src/hb-map.hh @@ -35,8 +35,8 @@ */ template <typename K, typename V, - K kINVALID = hb_is_pointer (K) ? 0 : hb_is_signed (K) ? hb_int_min (K) : (K) -1, - V vINVALID = hb_is_pointer (V) ? 0 : hb_is_signed (V) ? hb_int_min (V) : (V) -1> + K kINVALID = hb_is_pointer (K) ? 0 : std::is_signed<K>::value ? hb_int_min (K) : (K) -1, + V vINVALID = hb_is_pointer (V) ? 0 : std::is_signed<V>::value ? hb_int_min (V) : (V) -1> struct hb_hashmap_t { hb_hashmap_t () { init (); } @@ -59,8 +59,8 @@ struct hb_hashmap_t hb_copy (o, *this); } - static_assert (hb_is_integral (K) || hb_is_pointer (K), ""); - static_assert (hb_is_integral (V) || hb_is_pointer (V), ""); + static_assert (std::is_integral<K>::value || hb_is_pointer (K), ""); + static_assert (std::is_integral<V>::value || hb_is_pointer (V), ""); struct item_t { diff --git a/src/hb-meta.hh b/src/hb-meta.hh index 2a6f90a43..3808d917b 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -220,50 +220,6 @@ struct hb_reference_wrapper<T&> /* Type traits */ -template <typename T> -using hb_is_integral = hb_bool_constant< - hb_is_same (hb_decay<T>, char) || - hb_is_same (hb_decay<T>, signed char) || - hb_is_same (hb_decay<T>, unsigned char) || - hb_is_same (hb_decay<T>, signed int) || - hb_is_same (hb_decay<T>, unsigned int) || - hb_is_same (hb_decay<T>, signed short) || - hb_is_same (hb_decay<T>, unsigned short) || - hb_is_same (hb_decay<T>, signed long) || - hb_is_same (hb_decay<T>, unsigned long) || - hb_is_same (hb_decay<T>, signed long long) || - hb_is_same (hb_decay<T>, unsigned long long) || - false ->; -#define hb_is_integral(T) hb_is_integral<T>::value -template <typename T> -using hb_is_floating_point = hb_bool_constant< - hb_is_same (hb_decay<T>, float) || - hb_is_same (hb_decay<T>, double) || - hb_is_same (hb_decay<T>, long double) || - false ->; -#define hb_is_floating_point(T) hb_is_floating_point<T>::value -template <typename T> -using hb_is_arithmetic = hb_bool_constant< - hb_is_integral (T) || - hb_is_floating_point (T) || - false ->; -#define hb_is_arithmetic(T) hb_is_arithmetic<T>::value - - -template <typename T, bool is_arithmetic> struct hb_is_signed_; -template <typename T> struct hb_is_signed_<T, false> : hb_false_type {}; -template <typename T> struct hb_is_signed_<T, true> : hb_bool_constant<(T) -1 < (T) 0> {}; -template <typename T> struct hb_is_signed : hb_is_signed_<T, hb_is_arithmetic (T)> {}; -#define hb_is_signed(T) hb_is_signed<T>::value -template <typename T, bool is_arithmetic> struct hb_is_unsigned_; -template <typename T> struct hb_is_unsigned_<T, false> : hb_false_type {}; -template <typename T> struct hb_is_unsigned_<T, true> : hb_bool_constant<(T) 0 < (T) -1> {}; -template <typename T> struct hb_is_unsigned : hb_is_unsigned_<T, hb_is_arithmetic (T)> {}; -#define hb_is_unsigned(T) hb_is_unsigned<T>::value - template <typename T> struct hb_int_min; template <> struct hb_int_min<char> : hb_integral_constant<char, CHAR_MIN> {}; template <> struct hb_int_min<signed char> : hb_integral_constant<signed char, SCHAR_MIN> {}; diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index d3712f045..1504584f1 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -64,7 +64,7 @@ struct IntType IntType& operator = (Type i) { v = i; return *this; } /* For reason we define cast out operator for signed/unsigned, instead of Type, see: * https://github.com/harfbuzz/harfbuzz/pull/2875/commits/09836013995cab2b9f07577a179ad7b024130467 */ - operator hb_conditional<hb_is_signed (Type), signed, unsigned> () const { return v; } + operator hb_conditional<std::is_signed<Type>::value, signed, unsigned> () const { return v; } bool operator == (const IntType &o) const { return (Type) v == (Type) o.v; } bool operator != (const IntType &o) const { return !(*this == o); } @@ -86,7 +86,7 @@ struct IntType return pb->cmp (*pa); } template <typename Type2, - hb_enable_if (hb_is_integral (Type2) && + hb_enable_if (std::is_integral<Type2>::value && sizeof (Type2) < sizeof (int) && sizeof (Type) < sizeof (int))> int cmp (Type2 a) const diff --git a/src/hb-serialize.hh b/src/hb-serialize.hh index 77bad06b8..7b83fe1a2 100644 --- a/src/hb-serialize.hh +++ b/src/hb-serialize.hh @@ -376,7 +376,7 @@ struct hb_serialize_context_t err (HB_SERIALIZE_ERROR_OTHER); link.width = sizeof (T); - link.is_signed = hb_is_signed (hb_unwrap_type (T)); + link.is_signed = std::is_signed<hb_unwrap_type (T)>::value; link.whence = (unsigned) whence; link.position = (const char *) &ofs - current->head; link.bias = bias; diff --git a/src/test-meta.cc b/src/test-meta.cc index c6715ac58..0fb2385af 100644 --- a/src/test-meta.cc +++ b/src/test-meta.cc @@ -95,9 +95,6 @@ main (int argc, char **argv) static_assert (hb_is_base_of (X, const Y), ""); static_assert (!hb_is_base_of (Y, X), ""); - static_assert (hb_is_signed (hb_unwrap_type (U<U<U<int>>>)), ""); - static_assert (hb_is_unsigned (hb_unwrap_type (U<U<U<U<unsigned>>>>)), ""); - /* TODO Add more meaningful tests. */ return 0; |