From f99abcc37990a478189dda691d1fdac7b9d51386 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 24 Nov 2018 00:22:21 -0500 Subject: [PATCH] Add template-function convenience macros --- src/hb-atomic.hh | 2 +- src/hb-blob.hh | 4 ++-- src/hb-common.cc | 2 +- src/hb-ft.cc | 2 +- src/hb-null.hh | 11 ++++++----- src/hb.hh | 3 +++ 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/hb-atomic.hh b/src/hb-atomic.hh index 64ed257bd..265de1267 100644 --- a/src/hb-atomic.hh +++ b/src/hb-atomic.hh @@ -282,7 +282,7 @@ struct hb_atomic_int_t template struct hb_atomic_ptr_t { - typedef typename hb_remove_pointer

::value T; + typedef typename hb_remove_pointer (P) T; inline void init (T* v_ = nullptr) { set_relaxed (v_); } inline void set_relaxed (T* v_) { hb_atomic_ptr_impl_set_relaxed (&v, v_); } diff --git a/src/hb-blob.hh b/src/hb-blob.hh index 4f9d8f040..bf2132bda 100644 --- a/src/hb-blob.hh +++ b/src/hb-blob.hh @@ -60,7 +60,7 @@ struct hb_blob_t template inline const Type* as (void) const { - return length < hb_null_size::value ? &Null(Type) : reinterpret_cast (data); + return length < hb_null_size (Type) ? &Null(Type) : reinterpret_cast (data); } inline hb_bytes_t as_bytes (void) const { @@ -86,7 +86,7 @@ struct hb_blob_t template struct hb_blob_ptr_t { - typedef typename hb_remove_pointer

::value T; + typedef typename hb_remove_pointer (P) T; inline hb_blob_ptr_t (hb_blob_t *b_ = nullptr) : b (b_) {} inline hb_blob_t * operator = (hb_blob_t *b_) { return b = b_; } diff --git a/src/hb-common.cc b/src/hb-common.cc index b7f9ad68b..c3cffccb1 100644 --- a/src/hb-common.cc +++ b/src/hb-common.cc @@ -784,7 +784,7 @@ parse_uint32 (const char **pp, const char *end, uint32_t *pv) static void free_static_C_locale (void); #endif -static struct hb_C_locale_lazy_loader_t : hb_lazy_loader_t::value, +static struct hb_C_locale_lazy_loader_t : hb_lazy_loader_t { static inline HB_LOCALE_T create (void) diff --git a/src/hb-ft.cc b/src/hb-ft.cc index fff0e285a..633e0ecd2 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -748,7 +748,7 @@ hb_ft_font_create_referenced (FT_Face ft_face) static void free_static_ft_library (void); #endif -static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t::value, +static struct hb_ft_library_lazy_loader_t : hb_lazy_loader_t { static inline FT_Library create (void) diff --git a/src/hb-null.hh b/src/hb-null.hh index 58151d72b..c0cefc9a8 100644 --- a/src/hb-null.hh +++ b/src/hb-null.hh @@ -56,6 +56,7 @@ struct _hb_null_size > template struct hb_null_size { enum { value = _hb_null_size >::value }; }; +#define hb_null_size(T) hb_null_size::value extern HB_INTERNAL hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_size_impl_t) - 1) / sizeof (hb_vector_size_impl_t)]; @@ -63,10 +64,10 @@ hb_vector_size_impl_t const _hb_NullPool[(HB_NULL_POOL_SIZE + sizeof (hb_vector_ /* Generic nul-content Null objects. */ template static inline Type const & Null (void) { - static_assert (hb_null_size::value <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); + static_assert (hb_null_size (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); return *reinterpret_cast (_hb_NullPool); } -#define Null(Type) Null::value>::value>() +#define Null(Type) Null () /* Specializations for arbitrary-content Null objects expressed in bytes. */ #define DECLARE_NULL_NAMESPACE_BYTES(Namespace, Type) \ @@ -104,12 +105,12 @@ extern HB_INTERNAL /* CRAP pool: Common Region for Access Protection. */ template static inline Type& Crap (void) { - static_assert (hb_null_size::value <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); + static_assert (hb_null_size (Type) <= HB_NULL_POOL_SIZE, "Increase HB_NULL_POOL_SIZE."); Type *obj = reinterpret_cast (_hb_CrapPool); memcpy (obj, &Null(Type), sizeof (*obj)); return *obj; } -#define Crap(Type) Crap::value>::value>() +#define Crap(Type) Crap () template struct CrapOrNull { @@ -129,7 +130,7 @@ struct CrapOrNull { template struct hb_nonnull_ptr_t { - typedef typename hb_remove_pointer

::value T; + typedef typename hb_remove_pointer (P) T; inline hb_nonnull_ptr_t (T *v_ = nullptr) : v (v_) {} inline T * operator = (T *v_) { return v = v_; } diff --git a/src/hb.hh b/src/hb.hh index bc322a814..c771d1fb9 100644 --- a/src/hb.hh +++ b/src/hb.hh @@ -508,10 +508,13 @@ _hb_memalign(void **memptr, size_t alignment, size_t size) /* Some really basic things everyone wants. */ template struct hb_remove_const { typedef T value; }; template struct hb_remove_const { typedef T value; }; +#define hb_remove_const(T) hb_remove_const::value template struct hb_remove_reference { typedef T value; }; template struct hb_remove_reference { typedef T value; }; +#define hb_remove_reference(T) hb_remove_reference::value template struct hb_remove_pointer { typedef T value; }; template struct hb_remove_pointer { typedef T value; }; +#define hb_remove_pointer(T) hb_remove_pointer::value /* Headers we include for everyone. Keep sorted. They express dependency amongst