[meta] Use more std type_traits

This commit is contained in:
Behdad Esfahbod 2021-11-02 00:26:46 -06:00
parent 6d555ce82e
commit 943921cf0c
6 changed files with 10 additions and 57 deletions

View File

@ -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! */

View File

@ -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
{

View File

@ -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> {};

View File

@ -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

View File

@ -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;

View File

@ -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;