diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2018-11-30 01:09:56 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2018-11-30 01:09:56 +0000 |
commit | e2012ff38bc208db38b47955974acfb658dafa9e (patch) | |
tree | 442c6ab6fc137e3650ae5a969910c6f0d19aa0ea /Build/source/libs/harfbuzz/harfbuzz-src/src/hb-null.hh | |
parent | bfc1ab8d60cc7919762bc4d066355b1928690a76 (diff) |
harfbuzz-2.2.0
git-svn-id: svn://tug.org/texlive/trunk@49277 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/harfbuzz/harfbuzz-src/src/hb-null.hh')
-rw-r--r-- | Build/source/libs/harfbuzz/harfbuzz-src/src/hb-null.hh | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-null.hh b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-null.hh index 25a24f05cb4..1583d5b90e0 100644 --- a/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-null.hh +++ b/Build/source/libs/harfbuzz/harfbuzz-src/src/hb-null.hh @@ -38,21 +38,60 @@ #define HB_NULL_POOL_SIZE 1024 +/* Use SFINAE to sniff whether T has min_size; in which case return T::null_size, + * otherwise return sizeof(T). */ + +/* The hard way... + * https://stackoverflow.com/questions/7776448/sfinae-tried-with-bool-gives-compiler-error-template-argument-tvalue-invol + */ + +template<bool> struct _hb_bool_type {}; + +template <typename T, typename B> +struct _hb_null_size +{ enum { value = sizeof (T) }; }; +template <typename T> +struct _hb_null_size<T, _hb_bool_type<(bool) (1 + (unsigned int) T::min_size)> > +{ enum { value = T::null_size }; }; + +template <typename T> +struct hb_null_size +{ enum { value = _hb_null_size<T, _hb_bool_type<true> >::value }; }; +#define hb_null_size(T) hb_null_size<T>::value + +/* This doesn't belong here, but since is copy/paste from above, put it here. */ + +template <typename T, typename B> +struct _hb_static_size +{ enum { value = sizeof (T) }; }; +template <typename T> +struct _hb_static_size<T, _hb_bool_type<(bool) (1 + (unsigned int) T::min_size)> > +{ enum { value = T::static_size }; }; + +template <typename T> +struct hb_static_size +{ enum { value = _hb_static_size<T, _hb_bool_type<true> >::value }; }; +#define hb_static_size(T) hb_static_size<T>::value + + +/* + * Null() + */ 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)]; /* Generic nul-content Null objects. */ template <typename Type> static inline Type const & Null (void) { - static_assert (sizeof (Type) <= 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<Type const *> (_hb_NullPool); } -#define Null(Type) Null<typename hb_remove_const<typename hb_remove_reference<Type>::value>::value>() +#define Null(Type) Null<typename hb_remove_const (typename hb_remove_reference (Type))> () /* Specializations for arbitrary-content Null objects expressed in bytes. */ #define DECLARE_NULL_NAMESPACE_BYTES(Namespace, Type) \ } /* Close namespace. */ \ - extern HB_INTERNAL const unsigned char _hb_Null_##Namespace##_##Type[Namespace::Type::min_size]; \ + extern HB_INTERNAL const unsigned char _hb_Null_##Namespace##_##Type[Namespace::Type::null_size]; \ template <> \ /*static*/ inline const Namespace::Type& Null<Namespace::Type> (void) { \ return *reinterpret_cast<const Namespace::Type *> (_hb_Null_##Namespace##_##Type); \ @@ -60,7 +99,7 @@ static inline Type const & Null (void) { namespace Namespace { \ static_assert (true, "Just so we take semicolon after.") #define DEFINE_NULL_NAMESPACE_BYTES(Namespace, Type) \ - const unsigned char _hb_Null_##Namespace##_##Type[Namespace::Type::min_size] + const unsigned char _hb_Null_##Namespace##_##Type[Namespace::Type::null_size] /* Specializations for arbitrary-content Null objects expressed as struct initializer. */ #define DECLARE_NULL_INSTANCE(Type) \ @@ -85,12 +124,12 @@ extern HB_INTERNAL /* CRAP pool: Common Region for Access Protection. */ template <typename Type> static inline Type& Crap (void) { - static_assert (sizeof (Type) <= 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<Type *> (_hb_CrapPool); memcpy (obj, &Null(Type), sizeof (*obj)); return *obj; } -#define Crap(Type) Crap<typename hb_remove_const<typename hb_remove_reference<Type>::value>::value>() +#define Crap(Type) Crap<typename hb_remove_const (typename hb_remove_reference (Type))> () template <typename Type> struct CrapOrNull { @@ -110,7 +149,7 @@ struct CrapOrNull<const Type> { template <typename P> struct hb_nonnull_ptr_t { - typedef typename hb_remove_pointer<P>::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_; } |