From 05867d9f5315c7e4f49e5873a5aba6bba7121f04 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 9 May 2019 11:00:43 -0700 Subject: [PATCH] [meta] Add hb_int_max() --- src/hb-meta.hh | 91 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/src/hb-meta.hh b/src/hb-meta.hh index 4e5e5d9..74a4457 100644 --- a/src/hb-meta.hh +++ b/src/hb-meta.hh @@ -47,7 +47,7 @@ template using hb_head_tt = typename _hb_head_tt::type; /* Bool! For when we need to evaluate type-dependent expressions * in a template argument. */ -template struct hb_bool_tt { enum { value = b }; }; +template struct hb_bool_tt { static constexpr bool value = b; }; typedef hb_bool_tt hb_true_t; typedef hb_bool_tt hb_false_t; @@ -87,17 +87,17 @@ HB_FUNCOBJ (hb_addressof); template static inline T hb_declval (); #define hb_declval(T) (hb_declval ()) -template struct hb_match_const { typedef T type; enum { value = false }; }; -template struct hb_match_const { typedef T type; enum { value = true }; }; +template struct hb_match_const { typedef T type; static constexpr bool value = false; }; +template struct hb_match_const { typedef T type; static constexpr bool value = true; }; template using hb_remove_const = typename hb_match_const::type; #define hb_is_const(T) hb_match_const::value -template struct hb_match_reference { typedef T type; enum { value = false }; }; -template struct hb_match_reference { typedef T type; enum { value = true }; }; -template struct hb_match_reference { typedef T type; enum { value = true }; }; +template struct hb_match_reference { typedef T type; static constexpr bool value = false; }; +template struct hb_match_reference { typedef T type; static constexpr bool value = true; }; +template struct hb_match_reference { typedef T type; static constexpr bool value = true; }; template using hb_remove_reference = typename hb_match_reference::type; #define hb_is_reference(T) hb_match_reference::value -template struct hb_match_pointer { typedef T type; enum { value = false }; }; -template struct hb_match_pointer { typedef T type; enum { value = true }; }; +template struct hb_match_pointer { typedef T type; static constexpr bool value = false; }; +template struct hb_match_pointer { typedef T type; static constexpr bool value = true; }; template using hb_remove_pointer = typename hb_match_pointer::type; #define hb_is_pointer(T) hb_match_pointer::value @@ -173,42 +173,63 @@ template struct hb_is_same : hb_true_t {}; #define hb_is_same(T, T2) hb_is_same::value template struct hb_is_signed; -template <> struct hb_is_signed { enum { value = CHAR_MIN < 0 }; }; -template <> struct hb_is_signed { enum { value = true }; }; -template <> struct hb_is_signed { enum { value = false }; }; -template <> struct hb_is_signed { enum { value = true }; }; -template <> struct hb_is_signed { enum { value = false }; }; -template <> struct hb_is_signed { enum { value = true }; }; -template <> struct hb_is_signed { enum { value = false }; }; -template <> struct hb_is_signed { enum { value = true }; }; -template <> struct hb_is_signed { enum { value = false }; }; -template <> struct hb_is_signed { enum { value = true }; }; -template <> struct hb_is_signed { enum { value = false }; }; +template <> struct hb_is_signed { static constexpr bool value = CHAR_MIN < 0; }; +template <> struct hb_is_signed { static constexpr bool value = true; }; +template <> struct hb_is_signed { static constexpr bool value = false; }; +template <> struct hb_is_signed { static constexpr bool value = true; }; +template <> struct hb_is_signed { static constexpr bool value = false; }; +template <> struct hb_is_signed { static constexpr bool value = true; }; +template <> struct hb_is_signed { static constexpr bool value = false; }; +template <> struct hb_is_signed { static constexpr bool value = true; }; +template <> struct hb_is_signed { static constexpr bool value = false; }; +template <> struct hb_is_signed { static constexpr bool value = true; }; +template <> struct hb_is_signed { static constexpr bool value = false; }; #define hb_is_signed(T) hb_is_signed::value -template struct hb_int_min { static constexpr T value = 0; }; -template <> struct hb_int_min { static constexpr char value = CHAR_MIN; }; -template <> struct hb_int_min { static constexpr int value = INT_MIN; }; -template <> struct hb_int_min { static constexpr long value = LONG_MIN; }; +template struct hb_int_min; +template <> struct hb_int_min { static constexpr char value = CHAR_MIN; }; +template <> struct hb_int_min { static constexpr signed char value = SCHAR_MIN; }; +template <> struct hb_int_min { static constexpr unsigned char value = 0; }; +template <> struct hb_int_min { static constexpr signed short value = SHRT_MIN; }; +template <> struct hb_int_min { static constexpr unsigned short value = 0; }; +template <> struct hb_int_min { static constexpr signed int value = INT_MIN; }; +template <> struct hb_int_min { static constexpr unsigned int value = 0; }; +template <> struct hb_int_min { static constexpr signed long value = LONG_MIN; }; +template <> struct hb_int_min { static constexpr unsigned long value = 0; }; +template <> struct hb_int_min { static constexpr signed long long value = LLONG_MIN; }; +template <> struct hb_int_min { static constexpr unsigned long long value = 0; }; #define hb_int_min(T) hb_int_min::value +template struct hb_int_max; +template <> struct hb_int_max { static constexpr char value = CHAR_MAX; }; +template <> struct hb_int_max { static constexpr signed char value = SCHAR_MAX; }; +template <> struct hb_int_max { static constexpr unsigned char value = UCHAR_MAX; }; +template <> struct hb_int_max { static constexpr signed short value = SHRT_MAX; }; +template <> struct hb_int_max { static constexpr unsigned short value = USHRT_MAX; }; +template <> struct hb_int_max { static constexpr signed int value = INT_MAX; }; +template <> struct hb_int_max { static constexpr unsigned int value = UINT_MAX; }; +template <> struct hb_int_max { static constexpr signed long value = LONG_MAX; }; +template <> struct hb_int_max { static constexpr unsigned long value = ULONG_MAX; }; +template <> struct hb_int_max { static constexpr signed long long value = LLONG_MAX; }; +template <> struct hb_int_max { static constexpr unsigned long long value = ULLONG_MAX; }; +#define hb_int_max(T) hb_int_max::value template struct hb_signedness_int; template <> struct hb_signedness_int { typedef unsigned int value; }; template <> struct hb_signedness_int { typedef signed int value; }; #define hb_signedness_int(T) hb_signedness_int::value -template struct hb_is_integer { enum { value = false }; }; -template <> struct hb_is_integer { enum { value = true }; }; -template <> struct hb_is_integer { enum { value = true }; }; -template <> struct hb_is_integer { enum { value = true }; }; -template <> struct hb_is_integer { enum { value = true }; }; -template <> struct hb_is_integer { enum { value = true }; }; -template <> struct hb_is_integer { enum { value = true }; }; -template <> struct hb_is_integer { enum { value = true }; }; -template <> struct hb_is_integer { enum { value = true }; }; -template <> struct hb_is_integer { enum { value = true }; }; -template <> struct hb_is_integer { enum { value = true }; }; -template <> struct hb_is_integer { enum { value = true }; }; +template struct hb_is_integer { static constexpr bool value = false;}; +template <> struct hb_is_integer { static constexpr bool value = true; }; +template <> struct hb_is_integer { static constexpr bool value = true; }; +template <> struct hb_is_integer { static constexpr bool value = true; }; +template <> struct hb_is_integer { static constexpr bool value = true; }; +template <> struct hb_is_integer { static constexpr bool value = true; }; +template <> struct hb_is_integer { static constexpr bool value = true; }; +template <> struct hb_is_integer { static constexpr bool value = true; }; +template <> struct hb_is_integer { static constexpr bool value = true; }; +template <> struct hb_is_integer { static constexpr bool value = true; }; +template <> struct hb_is_integer { static constexpr bool value = true; }; +template <> struct hb_is_integer { static constexpr bool value = true; }; #define hb_is_integer(T) hb_is_integer::value -- 2.7.4