mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-19 05:51:05 +01:00
[meta] Use C++11 standard traits and numeric limits (#6554)
* [meta] Use C++11 standard traits for constants and SFINAE Replace the duplicated integral constants, boolean tags, enable_if, and is_same with their C++11 standard counterparts. Use std:: types at call sites and keep the convenience macros backed by standard traits. Define hb_match_*::type directly to avoid ambiguity with the type member inherited from std::integral_constant. Validation: full Meson suite (298 passed, 1 skipped); six focused GCC C++11 tests; Clang C++11 compilation checks. Assisted-by: Codex * [meta] Use standard type transformations and numeric limits Keep the short hb_remove_const and hb_remove_reference aliases while backing them with C++11 standard traits. Remove their unused matching specializations. Implement hb_int_min/max using std::numeric_limits. Require integral types and retain the pointer-minimum specialization returning nullptr. Parenthesize min/max calls for compatibility with platform macros. Validation: standard Meson suite (298 passed, 1 skipped); GCC, Clang, and 32/64-bit MinGW C++11 integer-bound probes with both char signs. Native probes also link without the C++ runtime at -O0. The isolated GCC C++11 debug suite passed 276 tests; check-symbols exposed an existing ARRAY_LENGTH integral_constant value export, reproduced with the previous commit's hb-meta.hh. Assisted-by: Codex * [meta] Remove unused pointer and rvalue reference helpers Remove hb_add_pointer and hb_add_rvalue_reference along with their overload helpers. They have no uses in tracked sources. Validation: meson test -C build (298 passed, 1 skipped). Assisted-by: Codex
This commit is contained in:
1 parent
b70acb123f
commit
978afca2a9
4 files changed
+43
-76
No files matched your search
+10
-10
@@ -256,8 +256,8 @@ template<typename Iter, typename Item>
|
||||
struct hb_is_iterator_of
|
||||
{
|
||||
template <typename Item2 = Item>
|
||||
static hb_true_type impl (hb_priority<2>, hb_iter_t<Iter, hb_type_identity<Item2>> *);
|
||||
static hb_false_type impl (hb_priority<0>, const void *);
|
||||
static std::true_type impl (hb_priority<2>, hb_iter_t<Iter, hb_type_identity<Item2>> *);
|
||||
static std::false_type impl (hb_priority<0>, const void *);
|
||||
|
||||
public:
|
||||
static constexpr bool value = decltype (impl (hb_prioritize, hb_declval (Iter*)))::value;
|
||||
@@ -275,10 +275,10 @@ struct hb_is_iterable
|
||||
private:
|
||||
|
||||
template <typename U>
|
||||
static auto impl (hb_priority<1>) -> decltype (hb_declval (U).iter (), hb_true_type ());
|
||||
static auto impl (hb_priority<1>) -> decltype (hb_declval (U).iter (), std::true_type ());
|
||||
|
||||
template <typename>
|
||||
static hb_false_type impl (hb_priority<0>);
|
||||
static std::false_type impl (hb_priority<0>);
|
||||
|
||||
public:
|
||||
static constexpr bool value = decltype (impl<T> (hb_prioritize))::value;
|
||||
@@ -293,10 +293,10 @@ struct hb_is_source_of
|
||||
private:
|
||||
template <typename Iter2 = Iter,
|
||||
hb_enable_if (hb_is_convertible (typename Iter2::item_t, hb_add_lvalue_reference<const Item>))>
|
||||
static hb_true_type impl (hb_priority<2>);
|
||||
static std::true_type impl (hb_priority<2>);
|
||||
template <typename Iter2 = Iter>
|
||||
static auto impl (hb_priority<1>) -> decltype (hb_declval (Iter2) >> hb_declval (Item &), hb_true_type ());
|
||||
static hb_false_type impl (hb_priority<0>);
|
||||
static auto impl (hb_priority<1>) -> decltype (hb_declval (Iter2) >> hb_declval (Item &), std::true_type ());
|
||||
static std::false_type impl (hb_priority<0>);
|
||||
|
||||
public:
|
||||
static constexpr bool value = decltype (impl (hb_prioritize))::value;
|
||||
@@ -309,10 +309,10 @@ struct hb_is_sink_of
|
||||
private:
|
||||
template <typename Iter2 = Iter,
|
||||
hb_enable_if (hb_is_convertible (typename Iter2::item_t, hb_add_lvalue_reference<Item>))>
|
||||
static hb_true_type impl (hb_priority<2>);
|
||||
static std::true_type impl (hb_priority<2>);
|
||||
template <typename Iter2 = Iter>
|
||||
static auto impl (hb_priority<1>) -> decltype (hb_declval (Iter2) << hb_declval (Item), hb_true_type ());
|
||||
static hb_false_type impl (hb_priority<0>);
|
||||
static auto impl (hb_priority<1>) -> decltype (hb_declval (Iter2) << hb_declval (Item), std::true_type ());
|
||||
static std::false_type impl (hb_priority<0>);
|
||||
|
||||
public:
|
||||
static constexpr bool value = decltype (impl (hb_prioritize))::value;
|
||||
|
||||
+20
-53
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "hb.hh"
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
@@ -48,27 +49,18 @@ template<typename... Ts> using hb_void_t = typename _hb_void_t<Ts...>::type;
|
||||
template<typename Head, typename... Ts> struct _hb_head_t { typedef Head type; };
|
||||
template<typename... Ts> using hb_head_t = typename _hb_head_t<Ts...>::type;
|
||||
|
||||
template <typename T, T v> struct hb_integral_constant { static constexpr T value = v; };
|
||||
template <bool b> using hb_bool_constant = hb_integral_constant<bool, b>;
|
||||
using hb_true_type = hb_bool_constant<true>;
|
||||
using hb_false_type = hb_bool_constant<false>;
|
||||
|
||||
/* Static-assert as expression. */
|
||||
template <bool cond> struct static_assert_expr;
|
||||
template <> struct static_assert_expr<true> : hb_false_type {};
|
||||
template <> struct static_assert_expr<true> : std::false_type {};
|
||||
#define static_assert_expr(C) static_assert_expr<C>::value
|
||||
|
||||
/* Basic type SFINAE. */
|
||||
|
||||
template <bool B, typename T = void> struct hb_enable_if {};
|
||||
template <typename T> struct hb_enable_if<true, T> { typedef T type; };
|
||||
#define hb_enable_if(Cond) typename hb_enable_if<(Cond)>::type* = nullptr
|
||||
#define hb_enable_if(Cond) typename std::enable_if<(Cond)>::type* = nullptr
|
||||
/* Concepts/Requires alias: */
|
||||
#define hb_requires(Cond) hb_enable_if((Cond))
|
||||
|
||||
template <typename T, typename T2> struct hb_is_same : hb_false_type {};
|
||||
template <typename T> struct hb_is_same<T, T> : hb_true_type {};
|
||||
#define hb_is_same(T, T2) hb_is_same<T, T2>::value
|
||||
#define hb_is_same(T, T2) std::is_same<T, T2>::value
|
||||
|
||||
/* Function overloading SFINAE and priority. */
|
||||
|
||||
@@ -89,27 +81,16 @@ template <typename T> using hb_type_identity = typename hb_type_identity_t<T>::t
|
||||
template <typename T> static inline T hb_declval ();
|
||||
#define hb_declval(T) (hb_declval<T> ())
|
||||
|
||||
template <typename T> struct hb_match_const : hb_type_identity_t<T>, hb_false_type {};
|
||||
template <typename T> struct hb_match_const<const T> : hb_type_identity_t<T>, hb_true_type {};
|
||||
template <typename T> using hb_remove_const = typename hb_match_const<T>::type;
|
||||
template <typename T> using hb_remove_const = typename std::remove_const<T>::type;
|
||||
|
||||
template <typename T> struct hb_match_reference : hb_type_identity_t<T>, hb_false_type {};
|
||||
template <typename T> struct hb_match_reference<T &> : hb_type_identity_t<T>, hb_true_type {};
|
||||
template <typename T> struct hb_match_reference<T &&> : hb_type_identity_t<T>, hb_true_type {};
|
||||
template <typename T> using hb_remove_reference = typename hb_match_reference<T>::type;
|
||||
template <typename T> using hb_remove_reference = typename std::remove_reference<T>::type;
|
||||
template <typename T> auto _hb_try_add_lvalue_reference (hb_priority<1>) -> hb_type_identity<T&>;
|
||||
template <typename T> auto _hb_try_add_lvalue_reference (hb_priority<0>) -> hb_type_identity<T>;
|
||||
template <typename T> using hb_add_lvalue_reference = decltype (_hb_try_add_lvalue_reference<T> (hb_prioritize));
|
||||
template <typename T> auto _hb_try_add_rvalue_reference (hb_priority<1>) -> hb_type_identity<T&&>;
|
||||
template <typename T> auto _hb_try_add_rvalue_reference (hb_priority<0>) -> hb_type_identity<T>;
|
||||
template <typename T> using hb_add_rvalue_reference = decltype (_hb_try_add_rvalue_reference<T> (hb_prioritize));
|
||||
|
||||
template <typename T> struct hb_match_pointer : hb_type_identity_t<T>, hb_false_type {};
|
||||
template <typename T> struct hb_match_pointer<T *> : hb_type_identity_t<T>, hb_true_type {};
|
||||
template <typename T> struct hb_match_pointer : std::false_type { typedef T type; };
|
||||
template <typename T> struct hb_match_pointer<T *> : std::true_type { typedef T type; };
|
||||
template <typename T> using hb_remove_pointer = typename hb_match_pointer<T>::type;
|
||||
template <typename T> auto _hb_try_add_pointer (hb_priority<1>) -> hb_type_identity<hb_remove_reference<T>*>;
|
||||
template <typename T> auto _hb_try_add_pointer (hb_priority<1>) -> hb_type_identity<T>;
|
||||
template <typename T> using hb_add_pointer = decltype (_hb_try_add_pointer<T> (hb_prioritize));
|
||||
|
||||
|
||||
template <typename T> using hb_decay = typename std::decay<T>::type;
|
||||
@@ -117,7 +98,7 @@ template <typename T> using hb_decay = typename std::decay<T>::type;
|
||||
#define hb_is_convertible(From,To) std::is_convertible<From, To>::value
|
||||
|
||||
template <typename From, typename To>
|
||||
using hb_is_cr_convertible = hb_bool_constant<
|
||||
using hb_is_cr_convertible = std::integral_constant<bool,
|
||||
hb_is_same (hb_decay<From>, hb_decay<To>) &&
|
||||
(!std::is_const<From>::value || std::is_const<To>::value) &&
|
||||
(!std::is_reference<To>::value || std::is_const<To>::value || std::is_reference<To>::value)
|
||||
@@ -171,32 +152,18 @@ struct hb_reference_wrapper<T&>
|
||||
|
||||
/* Type traits */
|
||||
|
||||
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> {};
|
||||
template <> struct hb_int_min<unsigned char> : hb_integral_constant<unsigned char, 0> {};
|
||||
template <> struct hb_int_min<signed short> : hb_integral_constant<signed short, SHRT_MIN> {};
|
||||
template <> struct hb_int_min<unsigned short> : hb_integral_constant<unsigned short, 0> {};
|
||||
template <> struct hb_int_min<signed int> : hb_integral_constant<signed int, INT_MIN> {};
|
||||
template <> struct hb_int_min<unsigned int> : hb_integral_constant<unsigned int, 0> {};
|
||||
template <> struct hb_int_min<signed long> : hb_integral_constant<signed long, LONG_MIN> {};
|
||||
template <> struct hb_int_min<unsigned long> : hb_integral_constant<unsigned long, 0> {};
|
||||
template <> struct hb_int_min<signed long long> : hb_integral_constant<signed long long, LLONG_MIN> {};
|
||||
template <> struct hb_int_min<unsigned long long> : hb_integral_constant<unsigned long long, 0> {};
|
||||
template <typename T> struct hb_int_min<T *> : hb_integral_constant<T *, nullptr> {};
|
||||
template <typename T>
|
||||
struct hb_int_min : std::integral_constant<T, (std::numeric_limits<T>::min) ()>
|
||||
{
|
||||
static_assert (std::is_integral<T>::value, "");
|
||||
};
|
||||
template <typename T> struct hb_int_min<T *> : std::integral_constant<T *, nullptr> {};
|
||||
#define hb_int_min(T) hb_int_min<T>::value
|
||||
template <typename T> struct hb_int_max;
|
||||
template <> struct hb_int_max<char> : hb_integral_constant<char, CHAR_MAX> {};
|
||||
template <> struct hb_int_max<signed char> : hb_integral_constant<signed char, SCHAR_MAX> {};
|
||||
template <> struct hb_int_max<unsigned char> : hb_integral_constant<unsigned char, UCHAR_MAX> {};
|
||||
template <> struct hb_int_max<signed short> : hb_integral_constant<signed short, SHRT_MAX> {};
|
||||
template <> struct hb_int_max<unsigned short> : hb_integral_constant<unsigned short, USHRT_MAX> {};
|
||||
template <> struct hb_int_max<signed int> : hb_integral_constant<signed int, INT_MAX> {};
|
||||
template <> struct hb_int_max<unsigned int> : hb_integral_constant<unsigned int, UINT_MAX> {};
|
||||
template <> struct hb_int_max<signed long> : hb_integral_constant<signed long, LONG_MAX> {};
|
||||
template <> struct hb_int_max<unsigned long> : hb_integral_constant<unsigned long, ULONG_MAX> {};
|
||||
template <> struct hb_int_max<signed long long> : hb_integral_constant<signed long long, LLONG_MAX> {};
|
||||
template <> struct hb_int_max<unsigned long long> : hb_integral_constant<unsigned long long, ULLONG_MAX> {};
|
||||
template <typename T>
|
||||
struct hb_int_max : std::integral_constant<T, (std::numeric_limits<T>::max) ()>
|
||||
{
|
||||
static_assert (std::is_integral<T>::value, "");
|
||||
};
|
||||
#define hb_int_max(T) hb_int_max<T>::value
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__)
|
||||
|
||||
+10
-10
@@ -40,19 +40,19 @@
|
||||
#define HB_NULL_POOL_SIZE 640
|
||||
|
||||
template <typename T, typename>
|
||||
struct _hb_has_min_size : hb_false_type {};
|
||||
struct _hb_has_min_size : std::false_type {};
|
||||
template <typename T>
|
||||
struct _hb_has_min_size<T, hb_void_t<decltype (T::min_size)>>
|
||||
: hb_true_type {};
|
||||
: std::true_type {};
|
||||
template <typename T>
|
||||
using hb_has_min_size = _hb_has_min_size<T, void>;
|
||||
#define hb_has_min_size(T) hb_has_min_size<T>::value
|
||||
|
||||
template <typename T, typename>
|
||||
struct _hb_has_null_size : hb_false_type {};
|
||||
struct _hb_has_null_size : std::false_type {};
|
||||
template <typename T>
|
||||
struct _hb_has_null_size<T, hb_void_t<decltype (T::null_size)>>
|
||||
: hb_true_type {};
|
||||
: std::true_type {};
|
||||
template <typename T>
|
||||
using hb_has_null_size = _hb_has_null_size<T, void>;
|
||||
#define hb_has_null_size(T) hb_has_null_size<T>::value
|
||||
@@ -68,10 +68,10 @@ using hb_has_null_size = _hb_has_null_size<T, void>;
|
||||
*/
|
||||
|
||||
template <typename T, typename>
|
||||
struct _hb_null_size : hb_integral_constant<unsigned, sizeof (T)> {};
|
||||
struct _hb_null_size : std::integral_constant<unsigned, sizeof (T)> {};
|
||||
template <typename T>
|
||||
struct _hb_null_size<T, hb_void_t<decltype (T::min_size)>>
|
||||
: hb_integral_constant<unsigned,
|
||||
: std::integral_constant<unsigned,
|
||||
(sizeof (T) > T::null_size ? sizeof (T) : T::null_size)> {};
|
||||
template <typename T>
|
||||
using hb_null_size = _hb_null_size<T, void>;
|
||||
@@ -83,17 +83,17 @@ using hb_null_size = _hb_null_size<T, void>;
|
||||
* Returns T::static_size if T::min_size is defined, or sizeof (T) otherwise. */
|
||||
|
||||
template <typename T, typename>
|
||||
struct _hb_static_size : hb_integral_constant<unsigned, sizeof (T)> {};
|
||||
struct _hb_static_size : std::integral_constant<unsigned, sizeof (T)> {};
|
||||
template <typename T>
|
||||
struct _hb_static_size<T, hb_void_t<decltype (T::static_size)>> : hb_integral_constant<unsigned, T::static_size> {};
|
||||
struct _hb_static_size<T, hb_void_t<decltype (T::static_size)>> : std::integral_constant<unsigned, T::static_size> {};
|
||||
template <typename T>
|
||||
using hb_static_size = _hb_static_size<T, void>;
|
||||
#define hb_static_size(T) hb_static_size<T>::value
|
||||
|
||||
template <typename T, typename>
|
||||
struct _hb_min_size : hb_integral_constant<unsigned, sizeof (T)> {};
|
||||
struct _hb_min_size : std::integral_constant<unsigned, sizeof (T)> {};
|
||||
template <typename T>
|
||||
struct _hb_min_size<T, hb_void_t<decltype (T::min_size)>> : hb_integral_constant<unsigned, T::min_size> {};
|
||||
struct _hb_min_size<T, hb_void_t<decltype (T::min_size)>> : std::integral_constant<unsigned, T::min_size> {};
|
||||
template <typename T>
|
||||
using hb_min_size = _hb_min_size<T, void>;
|
||||
#define hb_min_size(T) hb_min_size<T>::value
|
||||
|
||||
+3
-3
@@ -51,9 +51,9 @@ struct hb_result_err_t
|
||||
constexpr bool operator != (const hb_result_err_t<OtherE>& other) const { return error != other.error; }
|
||||
};
|
||||
|
||||
template <typename X> struct _hb_is_result_tag : hb_false_type {};
|
||||
template <typename X> struct _hb_is_result_tag<hb_result_ok_t<X>> : hb_true_type {};
|
||||
template <typename X> struct _hb_is_result_tag<hb_result_err_t<X>> : hb_true_type {};
|
||||
template <typename X> struct _hb_is_result_tag : std::false_type {};
|
||||
template <typename X> struct _hb_is_result_tag<hb_result_ok_t<X>> : std::true_type {};
|
||||
template <typename X> struct _hb_is_result_tag<hb_result_err_t<X>> : std::true_type {};
|
||||
|
||||
template <typename T>
|
||||
static inline constexpr hb_result_ok_t<T&&> Ok (T&& v)
|
||||
|
||||
Reference in new issue
Block a user