Behdad Esfahbod | e76a3ca | 2018-12-27 17:23:12 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2018 Google, Inc. |
| 3 | * |
| 4 | * This is part of HarfBuzz, a text shaping library. |
| 5 | * |
| 6 | * Permission is hereby granted, without written agreement and without |
| 7 | * license or royalty fees, to use, copy, modify, and distribute this |
| 8 | * software and its documentation for any purpose, provided that the |
| 9 | * above copyright notice and the following two paragraphs appear in |
| 10 | * all copies of this software. |
| 11 | * |
| 12 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 13 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 14 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 15 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 16 | * DAMAGE. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 21 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 22 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 23 | * |
| 24 | * Google Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
| 27 | #ifndef HB_META_HH |
| 28 | #define HB_META_HH |
| 29 | |
| 30 | #include "hb.hh" |
| 31 | |
Behdad Esfahbod | 1c50106 | 2022-01-15 13:08:21 -0700 | [diff] [blame] | 32 | #include <memory> |
Behdad Esfahbod | be42800 | 2021-11-02 00:04:18 -0600 | [diff] [blame] | 33 | #include <type_traits> |
Behdad Esfahbod | 811f80a | 2021-11-02 00:14:34 -0600 | [diff] [blame] | 34 | #include <utility> |
Behdad Esfahbod | be42800 | 2021-11-02 00:04:18 -0600 | [diff] [blame] | 35 | |
Behdad Esfahbod | e76a3ca | 2018-12-27 17:23:12 -0500 | [diff] [blame] | 36 | |
Behdad Esfahbod | e32bf39 | 2018-12-27 17:38:26 -0500 | [diff] [blame] | 37 | /* |
Behdad Esfahbod | e75b220 | 2019-01-28 21:26:23 -0500 | [diff] [blame] | 38 | * C++ template meta-programming & fundamentals used with them. |
Behdad Esfahbod | e32bf39 | 2018-12-27 17:38:26 -0500 | [diff] [blame] | 39 | */ |
| 40 | |
Behdad Esfahbod | c67a0d5 | 2019-04-17 10:20:02 -0400 | [diff] [blame] | 41 | /* Void! For when we need a expression-type of void. */ |
Behdad Esfahbod | 7df3ecf | 2019-05-10 20:43:26 -0700 | [diff] [blame] | 42 | struct hb_empty_t {}; |
Behdad Esfahbod | c67a0d5 | 2019-04-17 10:20:02 -0400 | [diff] [blame] | 43 | |
Behdad Esfahbod | caa3f92 | 2019-05-10 20:43:51 -0700 | [diff] [blame] | 44 | /* https://en.cppreference.com/w/cpp/types/void_t */ |
| 45 | template<typename... Ts> struct _hb_void_t { typedef void type; }; |
| 46 | template<typename... Ts> using hb_void_t = typename _hb_void_t<Ts...>::type; |
Behdad Esfahbod | c67a0d5 | 2019-04-17 10:20:02 -0400 | [diff] [blame] | 47 | |
Behdad Esfahbod | 40fb36a | 2019-05-10 21:01:19 -0700 | [diff] [blame] | 48 | template<typename Head, typename... Ts> struct _hb_head_t { typedef Head type; }; |
| 49 | template<typename... Ts> using hb_head_t = typename _hb_head_t<Ts...>::type; |
Behdad Esfahbod | c67a0d5 | 2019-04-17 10:20:02 -0400 | [diff] [blame] | 50 | |
Behdad Esfahbod | 61d150c | 2019-05-10 20:06:31 -0700 | [diff] [blame] | 51 | template <typename T, T v> struct hb_integral_constant { static constexpr T value = v; }; |
| 52 | template <bool b> using hb_bool_constant = hb_integral_constant<bool, b>; |
| 53 | using hb_true_type = hb_bool_constant<true>; |
| 54 | using hb_false_type = hb_bool_constant<false>; |
Behdad Esfahbod | c67a0d5 | 2019-04-17 10:20:02 -0400 | [diff] [blame] | 55 | |
Behdad Esfahbod | 017f6b0 | 2020-06-29 00:44:41 -0700 | [diff] [blame] | 56 | /* Static-assert as expression. */ |
| 57 | template <bool cond> struct static_assert_expr; |
| 58 | template <> struct static_assert_expr<true> : hb_false_type {}; |
| 59 | #define static_assert_expr(C) static_assert_expr<C>::value |
Behdad Esfahbod | c67a0d5 | 2019-04-17 10:20:02 -0400 | [diff] [blame] | 60 | |
Behdad Esfahbod | 70a49f2 | 2019-05-09 14:35:15 -0700 | [diff] [blame] | 61 | /* Basic type SFINAE. */ |
| 62 | |
| 63 | template <bool B, typename T = void> struct hb_enable_if {}; |
| 64 | template <typename T> struct hb_enable_if<true, T> { typedef T type; }; |
| 65 | #define hb_enable_if(Cond) typename hb_enable_if<(Cond)>::type* = nullptr |
| 66 | /* Concepts/Requires alias: */ |
| 67 | #define hb_requires(Cond) hb_enable_if((Cond)) |
| 68 | |
Behdad Esfahbod | 61d150c | 2019-05-10 20:06:31 -0700 | [diff] [blame] | 69 | template <typename T, typename T2> struct hb_is_same : hb_false_type {}; |
| 70 | template <typename T> struct hb_is_same<T, T> : hb_true_type {}; |
Behdad Esfahbod | 70a49f2 | 2019-05-09 14:35:15 -0700 | [diff] [blame] | 71 | #define hb_is_same(T, T2) hb_is_same<T, T2>::value |
| 72 | |
Behdad Esfahbod | fe30fcd | 2019-04-16 17:34:06 -0400 | [diff] [blame] | 73 | /* Function overloading SFINAE and priority. */ |
| 74 | |
Behdad Esfahbod | 40fb36a | 2019-05-10 21:01:19 -0700 | [diff] [blame] | 75 | #define HB_RETURN(Ret, E) -> hb_head_t<Ret, decltype ((E))> { return (E); } |
Behdad Esfahbod | 5b33427 | 2019-04-16 18:28:17 -0400 | [diff] [blame] | 76 | #define HB_AUTO_RETURN(E) -> decltype ((E)) { return (E); } |
Behdad Esfahbod | caa3f92 | 2019-05-10 20:43:51 -0700 | [diff] [blame] | 77 | #define HB_VOID_RETURN(E) -> hb_void_t<decltype ((E))> { (E); } |
Behdad Esfahbod | fe30fcd | 2019-04-16 17:34:06 -0400 | [diff] [blame] | 78 | |
| 79 | template <unsigned Pri> struct hb_priority : hb_priority<Pri - 1> {}; |
| 80 | template <> struct hb_priority<0> {}; |
| 81 | #define hb_prioritize hb_priority<16> () |
| 82 | |
Behdad Esfahbod | 02d864a | 2019-04-15 15:39:03 -0400 | [diff] [blame] | 83 | #define HB_FUNCOBJ(x) static_const x HB_UNUSED |
Behdad Esfahbod | e32bf39 | 2018-12-27 17:38:26 -0500 | [diff] [blame] | 84 | |
Behdad Esfahbod | c67a0d5 | 2019-04-17 10:20:02 -0400 | [diff] [blame] | 85 | |
Behdad Esfahbod | f9a96a0 | 2019-05-10 20:56:16 -0700 | [diff] [blame] | 86 | template <typename T> struct hb_type_identity_t { typedef T type; }; |
| 87 | template <typename T> using hb_type_identity = typename hb_type_identity_t<T>::type; |
Behdad Esfahbod | 750b65e | 2019-04-26 17:14:25 -0700 | [diff] [blame] | 88 | |
Behdad Esfahbod | b89d20d | 2018-12-28 16:41:04 -0500 | [diff] [blame] | 89 | template <typename T> static inline T hb_declval (); |
Behdad Esfahbod | a6c013b | 2019-01-08 14:27:51 -0500 | [diff] [blame] | 90 | #define hb_declval(T) (hb_declval<T> ()) |
Behdad Esfahbod | 8c6cbbd | 2018-12-28 14:29:09 -0500 | [diff] [blame] | 91 | |
Behdad Esfahbod | baf2166 | 2021-08-05 12:07:25 -0600 | [diff] [blame] | 92 | template <typename T> struct hb_match_const : hb_type_identity_t<T>, hb_false_type {}; |
| 93 | template <typename T> struct hb_match_const<const T> : hb_type_identity_t<T>, hb_true_type {}; |
Behdad Esfahbod | 54ece29 | 2019-04-16 16:45:53 -0400 | [diff] [blame] | 94 | template <typename T> using hb_remove_const = typename hb_match_const<T>::type; |
Behdad Esfahbod | 909dde9 | 2022-01-13 15:30:10 -0700 | [diff] [blame] | 95 | |
Behdad Esfahbod | baf2166 | 2021-08-05 12:07:25 -0600 | [diff] [blame] | 96 | template <typename T> struct hb_match_reference : hb_type_identity_t<T>, hb_false_type {}; |
| 97 | template <typename T> struct hb_match_reference<T &> : hb_type_identity_t<T>, hb_true_type {}; |
| 98 | template <typename T> struct hb_match_reference<T &&> : hb_type_identity_t<T>, hb_true_type {}; |
Behdad Esfahbod | 54ece29 | 2019-04-16 16:45:53 -0400 | [diff] [blame] | 99 | template <typename T> using hb_remove_reference = typename hb_match_reference<T>::type; |
Behdad Esfahbod | 9574de7 | 2019-05-10 19:29:32 -0700 | [diff] [blame] | 100 | template <typename T> auto _hb_try_add_lvalue_reference (hb_priority<1>) -> hb_type_identity<T&>; |
| 101 | template <typename T> auto _hb_try_add_lvalue_reference (hb_priority<0>) -> hb_type_identity<T>; |
| 102 | template <typename T> using hb_add_lvalue_reference = decltype (_hb_try_add_lvalue_reference<T> (hb_prioritize)); |
| 103 | template <typename T> auto _hb_try_add_rvalue_reference (hb_priority<1>) -> hb_type_identity<T&&>; |
| 104 | template <typename T> auto _hb_try_add_rvalue_reference (hb_priority<0>) -> hb_type_identity<T>; |
| 105 | template <typename T> using hb_add_rvalue_reference = decltype (_hb_try_add_rvalue_reference<T> (hb_prioritize)); |
Behdad Esfahbod | 909dde9 | 2022-01-13 15:30:10 -0700 | [diff] [blame] | 106 | |
Behdad Esfahbod | baf2166 | 2021-08-05 12:07:25 -0600 | [diff] [blame] | 107 | template <typename T> struct hb_match_pointer : hb_type_identity_t<T>, hb_false_type {}; |
| 108 | template <typename T> struct hb_match_pointer<T *> : hb_type_identity_t<T>, hb_true_type {}; |
Behdad Esfahbod | 54ece29 | 2019-04-16 16:45:53 -0400 | [diff] [blame] | 109 | template <typename T> using hb_remove_pointer = typename hb_match_pointer<T>::type; |
Behdad Esfahbod | 9574de7 | 2019-05-10 19:29:32 -0700 | [diff] [blame] | 110 | template <typename T> auto _hb_try_add_pointer (hb_priority<1>) -> hb_type_identity<hb_remove_reference<T>*>; |
| 111 | template <typename T> auto _hb_try_add_pointer (hb_priority<1>) -> hb_type_identity<T>; |
| 112 | template <typename T> using hb_add_pointer = decltype (_hb_try_add_pointer<T> (hb_prioritize)); |
Behdad Esfahbod | f64ea8f | 2018-12-30 18:49:34 -0500 | [diff] [blame] | 113 | |
Behdad Esfahbod | 9574de7 | 2019-05-10 19:29:32 -0700 | [diff] [blame] | 114 | |
Seigo Nonaka | c62d6f4 | 2023-03-01 19:52:57 +0900 | [diff] [blame] | 115 | template <typename T> using hb_decay = typename std::decay<T>::type; |
Behdad Esfahbod | 52bb034 | 2019-04-26 12:52:28 -0700 | [diff] [blame] | 116 | |
Behdad Esfahbod | b8724c6 | 2021-11-02 00:49:40 -0600 | [diff] [blame] | 117 | #define hb_is_convertible(From,To) std::is_convertible<From, To>::value |
Behdad Esfahbod | 30e4ae6 | 2019-05-10 11:26:39 -0700 | [diff] [blame] | 118 | |
Behdad Esfahbod | 69d9114 | 2019-05-09 15:24:14 -0700 | [diff] [blame] | 119 | template <typename From, typename To> |
Behdad Esfahbod | c3a456a | 2019-05-10 20:17:30 -0700 | [diff] [blame] | 120 | using hb_is_cr_convertible = hb_bool_constant< |
| 121 | hb_is_same (hb_decay<From>, hb_decay<To>) && |
Behdad Esfahbod | 3b2e604 | 2022-01-13 15:32:46 -0700 | [diff] [blame] | 122 | (!std::is_const<From>::value || std::is_const<To>::value) && |
| 123 | (!std::is_reference<To>::value || std::is_const<To>::value || std::is_reference<To>::value) |
Behdad Esfahbod | c3a456a | 2019-05-10 20:17:30 -0700 | [diff] [blame] | 124 | >; |
Behdad Esfahbod | 69d9114 | 2019-05-09 15:24:14 -0700 | [diff] [blame] | 125 | #define hb_is_cr_convertible(From,To) hb_is_cr_convertible<From, To>::value |
Behdad Esfahbod | 70a49f2 | 2019-05-09 14:35:15 -0700 | [diff] [blame] | 126 | |
Behdad Esfahbod | 7c9ceab | 2019-03-30 18:19:36 -0700 | [diff] [blame] | 127 | |
Behdad Esfahbod | fe30fcd | 2019-04-16 17:34:06 -0400 | [diff] [blame] | 128 | struct |
| 129 | { |
Behdad Esfahbod | 2e48fd0 | 2019-07-02 17:55:58 -0700 | [diff] [blame] | 130 | template <typename T> constexpr auto |
Behdad Esfahbod | 6d555ce | 2021-11-02 00:18:22 -0600 | [diff] [blame] | 131 | operator () (T&& v) const HB_AUTO_RETURN (std::forward<T> (v)) |
Behdad Esfahbod | fe30fcd | 2019-04-16 17:34:06 -0400 | [diff] [blame] | 132 | |
Behdad Esfahbod | 2e48fd0 | 2019-07-02 17:55:58 -0700 | [diff] [blame] | 133 | template <typename T> constexpr auto |
Behdad Esfahbod | 5b33427 | 2019-04-16 18:28:17 -0400 | [diff] [blame] | 134 | operator () (T *v) const HB_AUTO_RETURN (*v) |
Qunxin Liu | c335bf4 | 2022-09-26 13:01:20 -0700 | [diff] [blame] | 135 | |
| 136 | template <typename T> constexpr auto |
| 137 | operator () (const hb::shared_ptr<T>& v) const HB_AUTO_RETURN (*v) |
| 138 | |
| 139 | template <typename T> constexpr auto |
| 140 | operator () (hb::shared_ptr<T>& v) const HB_AUTO_RETURN (*v) |
| 141 | |
| 142 | template <typename T> constexpr auto |
| 143 | operator () (const hb::unique_ptr<T>& v) const HB_AUTO_RETURN (*v) |
| 144 | |
| 145 | template <typename T> constexpr auto |
| 146 | operator () (hb::unique_ptr<T>& v) const HB_AUTO_RETURN (*v) |
Behdad Esfahbod | 7654ebe | 2019-05-07 16:53:03 -0700 | [diff] [blame] | 147 | } |
| 148 | HB_FUNCOBJ (hb_deref); |
Behdad Esfahbod | fe30fcd | 2019-04-16 17:34:06 -0400 | [diff] [blame] | 149 | |
Behdad Esfahbod | 03a6816 | 2019-05-07 00:03:35 -0700 | [diff] [blame] | 150 | template <typename T> |
| 151 | struct hb_reference_wrapper |
| 152 | { |
| 153 | hb_reference_wrapper (T v) : v (v) {} |
Behdad Esfahbod | 03a6816 | 2019-05-07 00:03:35 -0700 | [diff] [blame] | 154 | bool operator == (const hb_reference_wrapper& o) const { return v == o.v; } |
| 155 | bool operator != (const hb_reference_wrapper& o) const { return v != o.v; } |
Behdad Esfahbod | 8903040 | 2019-05-07 00:13:11 -0700 | [diff] [blame] | 156 | operator T () const { return v; } |
Behdad Esfahbod | 03a6816 | 2019-05-07 00:03:35 -0700 | [diff] [blame] | 157 | T get () const { return v; } |
| 158 | T v; |
| 159 | }; |
| 160 | template <typename T> |
| 161 | struct hb_reference_wrapper<T&> |
| 162 | { |
Behdad Esfahbod | 8a69e00 | 2022-01-13 16:17:34 -0700 | [diff] [blame] | 163 | hb_reference_wrapper (T& v) : v (std::addressof (v)) {} |
Behdad Esfahbod | 03a6816 | 2019-05-07 00:03:35 -0700 | [diff] [blame] | 164 | bool operator == (const hb_reference_wrapper& o) const { return v == o.v; } |
| 165 | bool operator != (const hb_reference_wrapper& o) const { return v != o.v; } |
Behdad Esfahbod | 8903040 | 2019-05-07 00:13:11 -0700 | [diff] [blame] | 166 | operator T& () const { return *v; } |
| 167 | T& get () const { return *v; } |
Behdad Esfahbod | 03a6816 | 2019-05-07 00:03:35 -0700 | [diff] [blame] | 168 | T* v; |
| 169 | }; |
| 170 | |
Behdad Esfahbod | 7c9ceab | 2019-03-30 18:19:36 -0700 | [diff] [blame] | 171 | |
Behdad Esfahbod | 2caae4a | 2020-06-29 01:18:28 -0700 | [diff] [blame] | 172 | /* Type traits */ |
| 173 | |
Behdad Esfahbod | 05867d9 | 2019-05-09 11:00:43 -0700 | [diff] [blame] | 174 | template <typename T> struct hb_int_min; |
Behdad Esfahbod | 5252677 | 2019-05-10 20:49:52 -0700 | [diff] [blame] | 175 | template <> struct hb_int_min<char> : hb_integral_constant<char, CHAR_MIN> {}; |
| 176 | template <> struct hb_int_min<signed char> : hb_integral_constant<signed char, SCHAR_MIN> {}; |
| 177 | template <> struct hb_int_min<unsigned char> : hb_integral_constant<unsigned char, 0> {}; |
| 178 | template <> struct hb_int_min<signed short> : hb_integral_constant<signed short, SHRT_MIN> {}; |
| 179 | template <> struct hb_int_min<unsigned short> : hb_integral_constant<unsigned short, 0> {}; |
| 180 | template <> struct hb_int_min<signed int> : hb_integral_constant<signed int, INT_MIN> {}; |
| 181 | template <> struct hb_int_min<unsigned int> : hb_integral_constant<unsigned int, 0> {}; |
| 182 | template <> struct hb_int_min<signed long> : hb_integral_constant<signed long, LONG_MIN> {}; |
| 183 | template <> struct hb_int_min<unsigned long> : hb_integral_constant<unsigned long, 0> {}; |
| 184 | template <> struct hb_int_min<signed long long> : hb_integral_constant<signed long long, LLONG_MIN> {}; |
| 185 | template <> struct hb_int_min<unsigned long long> : hb_integral_constant<unsigned long long, 0> {}; |
Behdad Esfahbod | 95c888e | 2021-08-05 12:27:02 -0600 | [diff] [blame] | 186 | template <typename T> struct hb_int_min<T *> : hb_integral_constant<T *, nullptr> {}; |
Behdad Esfahbod | 22da123 | 2019-04-24 10:53:16 -0400 | [diff] [blame] | 187 | #define hb_int_min(T) hb_int_min<T>::value |
Behdad Esfahbod | 05867d9 | 2019-05-09 11:00:43 -0700 | [diff] [blame] | 188 | template <typename T> struct hb_int_max; |
Behdad Esfahbod | 5252677 | 2019-05-10 20:49:52 -0700 | [diff] [blame] | 189 | template <> struct hb_int_max<char> : hb_integral_constant<char, CHAR_MAX> {}; |
| 190 | template <> struct hb_int_max<signed char> : hb_integral_constant<signed char, SCHAR_MAX> {}; |
| 191 | template <> struct hb_int_max<unsigned char> : hb_integral_constant<unsigned char, UCHAR_MAX> {}; |
| 192 | template <> struct hb_int_max<signed short> : hb_integral_constant<signed short, SHRT_MAX> {}; |
| 193 | template <> struct hb_int_max<unsigned short> : hb_integral_constant<unsigned short, USHRT_MAX> {}; |
| 194 | template <> struct hb_int_max<signed int> : hb_integral_constant<signed int, INT_MAX> {}; |
| 195 | template <> struct hb_int_max<unsigned int> : hb_integral_constant<unsigned int, UINT_MAX> {}; |
| 196 | template <> struct hb_int_max<signed long> : hb_integral_constant<signed long, LONG_MAX> {}; |
| 197 | template <> struct hb_int_max<unsigned long> : hb_integral_constant<unsigned long, ULONG_MAX> {}; |
| 198 | template <> struct hb_int_max<signed long long> : hb_integral_constant<signed long long, LLONG_MAX> {}; |
| 199 | template <> struct hb_int_max<unsigned long long> : hb_integral_constant<unsigned long long, ULLONG_MAX> {}; |
Behdad Esfahbod | 05867d9 | 2019-05-09 11:00:43 -0700 | [diff] [blame] | 200 | #define hb_int_max(T) hb_int_max<T>::value |
Behdad Esfahbod | 22da123 | 2019-04-24 10:53:16 -0400 | [diff] [blame] | 201 | |
Khaled Hosny | c0d60bd | 2022-07-19 18:21:09 +0200 | [diff] [blame] | 202 | #if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__) |
Thomas Devoogdt | c657c4e | 2022-05-10 10:00:06 +0200 | [diff] [blame] | 203 | #define hb_is_trivially_copyable(T) __has_trivial_copy(T) |
Behdad Esfahbod | 679b900 | 2022-05-19 15:27:32 -0600 | [diff] [blame] | 204 | #define hb_is_trivially_copy_assignable(T) __has_trivial_assign(T) |
Thomas Devoogdt | c657c4e | 2022-05-10 10:00:06 +0200 | [diff] [blame] | 205 | #define hb_is_trivially_constructible(T) __has_trivial_constructor(T) |
Behdad Esfahbod | fb77f48 | 2022-05-19 15:02:10 -0600 | [diff] [blame] | 206 | #define hb_is_trivially_copy_constructible(T) __has_trivial_copy_constructor(T) |
Thomas Devoogdt | c657c4e | 2022-05-10 10:00:06 +0200 | [diff] [blame] | 207 | #define hb_is_trivially_destructible(T) __has_trivial_destructor(T) |
| 208 | #else |
| 209 | #define hb_is_trivially_copyable(T) std::is_trivially_copyable<T>::value |
| 210 | #define hb_is_trivially_copy_assignable(T) std::is_trivially_copy_assignable<T>::value |
| 211 | #define hb_is_trivially_constructible(T) std::is_trivially_constructible<T>::value |
Behdad Esfahbod | fb77f48 | 2022-05-19 15:02:10 -0600 | [diff] [blame] | 212 | #define hb_is_trivially_copy_constructible(T) std::is_trivially_copy_constructible<T>::value |
Thomas Devoogdt | c657c4e | 2022-05-10 10:00:06 +0200 | [diff] [blame] | 213 | #define hb_is_trivially_destructible(T) std::is_trivially_destructible<T>::value |
| 214 | #endif |
Behdad Esfahbod | 442f4a5 | 2018-12-28 14:34:00 -0500 | [diff] [blame] | 215 | |
Behdad Esfahbod | 2caae4a | 2020-06-29 01:18:28 -0700 | [diff] [blame] | 216 | /* Class traits. */ |
| 217 | |
| 218 | #define HB_DELETE_COPY_ASSIGN(TypeName) \ |
| 219 | TypeName(const TypeName&) = delete; \ |
| 220 | void operator=(const TypeName&) = delete |
| 221 | #define HB_DELETE_CREATE_COPY_ASSIGN(TypeName) \ |
| 222 | TypeName() = delete; \ |
| 223 | TypeName(const TypeName&) = delete; \ |
| 224 | void operator=(const TypeName&) = delete |
Behdad Esfahbod | 086772e | 2019-05-10 21:49:25 -0700 | [diff] [blame] | 225 | |
ariza | 168ceea | 2020-02-14 11:56:56 -0800 | [diff] [blame] | 226 | /* hb_unwrap_type (T) |
| 227 | * If T has no T::type, returns T. Otherwise calls itself on T::type recursively. |
ariza | 71552ec | 2020-02-13 12:58:22 -0800 | [diff] [blame] | 228 | */ |
| 229 | |
| 230 | template <typename T, typename> |
ariza | 168ceea | 2020-02-14 11:56:56 -0800 | [diff] [blame] | 231 | struct _hb_unwrap_type : hb_type_identity_t<T> {}; |
ariza | 71552ec | 2020-02-13 12:58:22 -0800 | [diff] [blame] | 232 | template <typename T> |
ariza | 168ceea | 2020-02-14 11:56:56 -0800 | [diff] [blame] | 233 | struct _hb_unwrap_type<T, hb_void_t<typename T::type>> : _hb_unwrap_type<typename T::type, void> {}; |
ariza | 71552ec | 2020-02-13 12:58:22 -0800 | [diff] [blame] | 234 | template <typename T> |
ariza | 168ceea | 2020-02-14 11:56:56 -0800 | [diff] [blame] | 235 | using hb_unwrap_type = _hb_unwrap_type<T, void>; |
| 236 | #define hb_unwrap_type(T) typename hb_unwrap_type<T>::type |
Behdad Esfahbod | b147452 | 2019-05-10 21:42:59 -0700 | [diff] [blame] | 237 | |
Behdad Esfahbod | e76a3ca | 2018-12-27 17:23:12 -0500 | [diff] [blame] | 238 | #endif /* HB_META_HH */ |