w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

hb-meta.hh
Go to the documentation of this file.
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 
32 
33 /*
34  * C++ template meta-programming & fundamentals used with them.
35  */
36 
37 /* Void! For when we need a expression-type of void. */
38 struct hb_empty_t {};
39 
40 /* https://en.cppreference.com/w/cpp/types/void_t */
41 template<typename... Ts> struct _hb_void_t { typedef void type; };
42 template<typename... Ts> using hb_void_t = typename _hb_void_t<Ts...>::type;
43 
44 template<typename Head, typename... Ts> struct _hb_head_t { typedef Head type; };
45 template<typename... Ts> using hb_head_t = typename _hb_head_t<Ts...>::type;
46 
47 template <typename T, T v> struct hb_integral_constant { static constexpr T value = v; };
51 
52 
53 /* Basic type SFINAE. */
54 
55 template <bool B, typename T = void> struct hb_enable_if {};
56 template <typename T> struct hb_enable_if<true, T> { typedef T type; };
57 #define hb_enable_if(Cond) typename hb_enable_if<(Cond)>::type* = nullptr
58 /* Concepts/Requires alias: */
59 #define hb_requires(Cond) hb_enable_if((Cond))
60 
61 template <typename T, typename T2> struct hb_is_same : hb_false_type {};
62 template <typename T> struct hb_is_same<T, T> : hb_true_type {};
63 #define hb_is_same(T, T2) hb_is_same<T, T2>::value
64 
65 /* Function overloading SFINAE and priority. */
66 
67 #define HB_RETURN(Ret, E) -> hb_head_t<Ret, decltype ((E))> { return (E); }
68 #define HB_AUTO_RETURN(E) -> decltype ((E)) { return (E); }
69 #define HB_VOID_RETURN(E) -> hb_void_t<decltype ((E))> { (E); }
70 
71 template <unsigned Pri> struct hb_priority : hb_priority<Pri - 1> {};
72 template <> struct hb_priority<0> {};
73 #define hb_prioritize hb_priority<16> ()
74 
75 #define HB_FUNCOBJ(x) static_const x HB_UNUSED
76 
77 
78 template <typename T> struct hb_type_identity_t { typedef T type; };
79 template <typename T> using hb_type_identity = typename hb_type_identity_t<T>::type;
80 
81 struct
82 {
83  template <typename T> constexpr T*
84  operator () (T& arg) const
85  {
86 #pragma GCC diagnostic push
87 #pragma GCC diagnostic ignored "-Wcast-align"
88  /* https://en.cppreference.com/w/cpp/memory/addressof */
89  return reinterpret_cast<T*> (
90  &const_cast<char&> (
91  reinterpret_cast<const volatile char&> (arg)));
92 #pragma GCC diagnostic pop
93  }
94 }
96 
97 template <typename T> static inline T hb_declval ();
98 #define hb_declval(T) (hb_declval<T> ())
99 
100 template <typename T> struct hb_match_const : hb_type_identity_t<T>, hb_bool_constant<false>{};
101 template <typename T> struct hb_match_const<const T> : hb_type_identity_t<T>, hb_bool_constant<true> {};
102 template <typename T> using hb_remove_const = typename hb_match_const<T>::type;
103 template <typename T> using hb_add_const = const T;
104 #define hb_is_const(T) hb_match_const<T>::value
105 template <typename T> struct hb_match_reference : hb_type_identity_t<T>, hb_bool_constant<false>{};
106 template <typename T> struct hb_match_reference<T &> : hb_type_identity_t<T>, hb_bool_constant<true> {};
107 template <typename T> struct hb_match_reference<T &&> : hb_type_identity_t<T>, hb_bool_constant<true> {};
108 template <typename T> using hb_remove_reference = typename hb_match_reference<T>::type;
111 template <typename T> using hb_add_lvalue_reference = decltype (_hb_try_add_lvalue_reference<T> (hb_prioritize));
114 template <typename T> using hb_add_rvalue_reference = decltype (_hb_try_add_rvalue_reference<T> (hb_prioritize));
115 #define hb_is_reference(T) hb_match_reference<T>::value
116 template <typename T> struct hb_match_pointer : hb_type_identity_t<T>, hb_bool_constant<false>{};
117 template <typename T> struct hb_match_pointer<T *> : hb_type_identity_t<T>, hb_bool_constant<true> {};
118 template <typename T> using hb_remove_pointer = typename hb_match_pointer<T>::type;
120 template <typename T> auto _hb_try_add_pointer (hb_priority<1>) -> hb_type_identity<T>;
121 template <typename T> using hb_add_pointer = decltype (_hb_try_add_pointer<T> (hb_prioritize));
122 #define hb_is_pointer(T) hb_match_pointer<T>::value
123 
124 
125 /* TODO Add feature-parity to std::decay. */
126 template <typename T> using hb_decay = hb_remove_const<hb_remove_reference<T>>;
127 
128 
129 template<bool B, class T, class F>
130 struct _hb_conditional { typedef T type; };
131 template<class T, class F>
132 struct _hb_conditional<false, T, F> { typedef F type; };
133 template<bool B, class T, class F>
135 
136 
137 template <typename From, typename To>
139 {
140  private:
141  static constexpr bool from_void = hb_is_same (void, hb_decay<From>);
142  static constexpr bool to_void = hb_is_same (void, hb_decay<To> );
143  static constexpr bool either_void = from_void || to_void;
144  static constexpr bool both_void = from_void && to_void;
145 
147 
148  template <typename T>
149  static auto impl (hb_priority<1>) -> decltype (impl2 (hb_declval (T)));
150  template <typename T>
152  public:
153  static constexpr bool value = both_void ||
154  (!either_void &&
156 };
157 #define hb_is_convertible(From,To) hb_is_convertible<From, To>::value
158 
159 template <typename Base, typename Derived>
161 #define hb_is_base_of(Base,Derived) hb_is_base_of<Base, Derived>::value
162 
163 template <typename From, typename To>
166  (!hb_is_const (From) || hb_is_const (To)) &&
167  (!hb_is_reference (To) || hb_is_const (To) || hb_is_reference (To))
168 >;
169 #define hb_is_cr_convertible(From,To) hb_is_cr_convertible<From, To>::value
170 
171 /* std::move and std::forward */
172 
173 template <typename T>
174 static constexpr hb_remove_reference<T>&& hb_move (T&& t) { return (hb_remove_reference<T>&&) (t); }
175 
176 template <typename T>
177 static constexpr T&& hb_forward (hb_remove_reference<T>& t) { return (T&&) t; }
178 template <typename T>
179 static constexpr T&& hb_forward (hb_remove_reference<T>&& t) { return (T&&) t; }
180 
181 struct
182 {
183  template <typename T> constexpr auto
184  operator () (T&& v) const HB_AUTO_RETURN (hb_forward<T> (v))
185 
186  template <typename T> constexpr auto
187  operator () (T *v) const HB_AUTO_RETURN (*v)
188 }
190 
191 struct
192 {
193  template <typename T> constexpr auto
194  operator () (T&& v) const HB_AUTO_RETURN (hb_forward<T> (v))
195 
196  template <typename T> constexpr auto
197  operator () (T& v) const HB_AUTO_RETURN (hb_addressof (v))
198 }
200 
201 template <typename T>
203 {
205  bool operator == (const hb_reference_wrapper& o) const { return v == o.v; }
206  bool operator != (const hb_reference_wrapper& o) const { return v != o.v; }
207  operator T () const { return v; }
208  T get () const { return v; }
209  T v;
210 };
211 template <typename T>
213 {
215  bool operator == (const hb_reference_wrapper& o) const { return v == o.v; }
216  bool operator != (const hb_reference_wrapper& o) const { return v != o.v; }
217  operator T& () const { return *v; }
218  T& get () const { return *v; }
219  T* v;
220 };
221 
222 
223 template <typename T>
225  hb_is_same (hb_decay<T>, char) ||
226  hb_is_same (hb_decay<T>, signed char) ||
227  hb_is_same (hb_decay<T>, unsigned char) ||
228  hb_is_same (hb_decay<T>, signed int) ||
229  hb_is_same (hb_decay<T>, unsigned int) ||
230  hb_is_same (hb_decay<T>, signed short) ||
231  hb_is_same (hb_decay<T>, unsigned short) ||
232  hb_is_same (hb_decay<T>, signed long) ||
233  hb_is_same (hb_decay<T>, unsigned long) ||
234  hb_is_same (hb_decay<T>, signed long long) ||
235  hb_is_same (hb_decay<T>, unsigned long long) ||
236  false
237 >;
238 #define hb_is_integral(T) hb_is_integral<T>::value
239 template <typename T>
241  hb_is_same (hb_decay<T>, float) ||
242  hb_is_same (hb_decay<T>, double) ||
243  hb_is_same (hb_decay<T>, long double) ||
244  false
245 >;
246 #define hb_is_floating_point(T) hb_is_floating_point<T>::value
247 template <typename T>
249  hb_is_integral (T) ||
251  false
252 >;
253 #define hb_is_arithmetic(T) hb_is_arithmetic<T>::value
254 
255 
256 template <typename T>
258  hb_bool_constant<(T) -1 < (T) 0>,
259  hb_false_type>;
260 #define hb_is_signed(T) hb_is_signed<T>::value
261 template <typename T>
263  hb_bool_constant<(T) 0 < (T) -1>,
264  hb_false_type>;
265 #define hb_is_unsigned(T) hb_is_unsigned<T>::value
266 
267 template <typename T> struct hb_int_min;
268 template <> struct hb_int_min<char> : hb_integral_constant<char, CHAR_MIN> {};
269 template <> struct hb_int_min<signed char> : hb_integral_constant<signed char, SCHAR_MIN> {};
270 template <> struct hb_int_min<unsigned char> : hb_integral_constant<unsigned char, 0> {};
271 template <> struct hb_int_min<signed short> : hb_integral_constant<signed short, SHRT_MIN> {};
272 template <> struct hb_int_min<unsigned short> : hb_integral_constant<unsigned short, 0> {};
273 template <> struct hb_int_min<signed int> : hb_integral_constant<signed int, INT_MIN> {};
274 template <> struct hb_int_min<unsigned int> : hb_integral_constant<unsigned int, 0> {};
275 template <> struct hb_int_min<signed long> : hb_integral_constant<signed long, LONG_MIN> {};
276 template <> struct hb_int_min<unsigned long> : hb_integral_constant<unsigned long, 0> {};
277 template <> struct hb_int_min<signed long long> : hb_integral_constant<signed long long, LLONG_MIN> {};
278 template <> struct hb_int_min<unsigned long long> : hb_integral_constant<unsigned long long, 0> {};
279 #define hb_int_min(T) hb_int_min<T>::value
280 template <typename T> struct hb_int_max;
281 template <> struct hb_int_max<char> : hb_integral_constant<char, CHAR_MAX> {};
282 template <> struct hb_int_max<signed char> : hb_integral_constant<signed char, SCHAR_MAX> {};
283 template <> struct hb_int_max<unsigned char> : hb_integral_constant<unsigned char, UCHAR_MAX> {};
284 template <> struct hb_int_max<signed short> : hb_integral_constant<signed short, SHRT_MAX> {};
285 template <> struct hb_int_max<unsigned short> : hb_integral_constant<unsigned short, USHRT_MAX> {};
286 template <> struct hb_int_max<signed int> : hb_integral_constant<signed int, INT_MAX> {};
287 template <> struct hb_int_max<unsigned int> : hb_integral_constant<unsigned int, UINT_MAX> {};
288 template <> struct hb_int_max<signed long> : hb_integral_constant<signed long, LONG_MAX> {};
289 template <> struct hb_int_max<unsigned long> : hb_integral_constant<unsigned long, ULONG_MAX> {};
290 template <> struct hb_int_max<signed long long> : hb_integral_constant<signed long long, LLONG_MAX> {};
291 template <> struct hb_int_max<unsigned long long> : hb_integral_constant<unsigned long long, ULLONG_MAX> {};
292 #define hb_int_max(T) hb_int_max<T>::value
293 
294 
295 
296 template <typename T, typename>
298 template <typename T>
299 struct _hb_is_destructible<T, hb_void_t<decltype (hb_declval (T).~T ())>> : hb_true_type {};
300 template <typename T>
302 #define hb_is_destructible(T) hb_is_destructible<T>::value
303 
304 template <typename T, typename, typename ...Ts>
306 template <typename T, typename ...Ts>
307 struct _hb_is_constructible<T, hb_void_t<decltype (T (hb_declval (Ts)...))>, Ts...> : hb_true_type {};
308 template <typename T, typename ...Ts>
310 #define hb_is_constructible(...) hb_is_constructible<__VA_ARGS__>::value
311 
312 template <typename T>
314 #define hb_is_default_constructible(T) hb_is_default_constructible<T>::value
315 
316 template <typename T>
318 #define hb_is_copy_constructible(T) hb_is_copy_constructible<T>::value
319 
320 template <typename T>
322 #define hb_is_move_constructible(T) hb_is_move_constructible<T>::value
323 
324 template <typename T, typename U, typename>
326 template <typename T, typename U>
327 struct _hb_is_assignable<T, U, hb_void_t<decltype (hb_declval (T) = hb_declval (U))>> : hb_true_type {};
328 template <typename T, typename U>
330 #define hb_is_assignable(T,U) hb_is_assignable<T, U>::value
331 
332 template <typename T>
335 #define hb_is_copy_assignable(T) hb_is_copy_assignable<T>::value
336 
337 template <typename T>
340 #define hb_is_move_assignable(T) hb_is_move_assignable<T>::value
341 
342 /* Trivial versions. */
343 
344 template <typename T> union hb_trivial { T value; };
345 
346 template <typename T>
348 #define hb_is_trivially_destructible(T) hb_is_trivially_destructible<T>::value
349 
350 /* Don't know how to do the following. */
351 //template <typename T, typename ...Ts>
352 //using hb_is_trivially_constructible= hb_is_constructible<hb_trivial<T>, hb_trivial<Ts>...>;
353 //#define hb_is_trivially_constructible(...) hb_is_trivially_constructible<__VA_ARGS__>::value
354 
355 template <typename T>
357 #define hb_is_trivially_default_constructible(T) hb_is_trivially_default_constructible<T>::value
358 
359 template <typename T>
361 #define hb_is_trivially_copy_constructible(T) hb_is_trivially_copy_constructible<T>::value
362 
363 template <typename T>
365 #define hb_is_trivially_move_constructible(T) hb_is_trivially_move_constructible<T>::value
366 
367 /* Don't know how to do the following. */
368 //template <typename T, typename U>
369 //using hb_is_trivially_assignable= hb_is_assignable<hb_trivial<T>, hb_trivial<U>>;
370 //#define hb_is_trivially_assignable(T,U) hb_is_trivially_assignable<T, U>::value
371 
372 template <typename T>
374 #define hb_is_trivially_copy_assignable(T) hb_is_trivially_copy_assignable<T>::value
375 
376 template <typename T>
378 #define hb_is_trivially_move_assignable(T) hb_is_trivially_move_assignable<T>::value
379 
380 template <typename T>
387  true
388 >;
389 #define hb_is_trivially_copyable(T) hb_is_trivially_copyable<T>::value
390 
391 template <typename T>
395 >;
396 #define hb_is_trivial(T) hb_is_trivial<T>::value
397 
398 /* hb_unwrap_type (T)
399  * If T has no T::type, returns T. Otherwise calls itself on T::type recursively.
400  */
401 
402 template <typename T, typename>
404 template <typename T>
405 struct _hb_unwrap_type<T, hb_void_t<typename T::type>> : _hb_unwrap_type<typename T::type, void> {};
406 template <typename T>
408 #define hb_unwrap_type(T) typename hb_unwrap_type<T>::type
409 
410 #endif /* HB_META_HH */
#define type(a)
Definition: aptex-macros.h:171
#define typename
Definition: cppcomp.h:112
int v
Definition: dviconv.c:10
static void
Definition: fpif.c:118
#define t
Definition: afcover.h:96
static uint16_t *FN() Head(void *extra)
#define F(x, y, z)
Definition: md5.c:51
#define const
Definition: ftzconf.h:91
#define true
Definition: ftrandom.c:51
#define false
Definition: ftrandom.c:52
typename hb_type_identity_t< T >::type hb_type_identity
Definition: hb-meta.hh:79
#define hb_is_trivially_destructible(T)
Definition: hb-meta.hh:348
#define hb_is_floating_point(T)
Definition: hb-meta.hh:246
typename hb_match_pointer< T >::type hb_remove_pointer
Definition: hb-meta.hh:118
#define hb_is_move_assignable(T)
Definition: hb-meta.hh:340
#define hb_is_trivially_move_constructible(T)
Definition: hb-meta.hh:365
decltype(_hb_try_add_rvalue_reference< T >(hb_priority< 16 >())) hb_add_rvalue_reference
Definition: hb-meta.hh:114
struct @1061 hb_deref
typename hb_match_const< T >::type hb_remove_const
Definition: hb-meta.hh:102
#define hb_is_trivially_move_assignable(T)
Definition: hb-meta.hh:378
#define hb_is_trivially_copyable(T)
Definition: hb-meta.hh:389
#define hb_declval(T)
Definition: hb-meta.hh:98
typename _hb_head_t< Ts... >::type hb_head_t
Definition: hb-meta.hh:45
#define hb_is_const(T)
Definition: hb-meta.hh:104
typename _hb_conditional< B, T, F >::type hb_conditional
Definition: hb-meta.hh:134
hb_remove_const< hb_remove_reference< T > > hb_decay
Definition: hb-meta.hh:126
static constexpr hb_remove_reference< T > && hb_move(T &&t)
Definition: hb-meta.hh:174
#define hb_is_trivially_default_constructible(T)
Definition: hb-meta.hh:357
typename _hb_void_t< Ts... >::type hb_void_t
Definition: hb-meta.hh:42
decltype(_hb_try_add_lvalue_reference< T >(hb_priority< 16 >())) hb_add_lvalue_reference
Definition: hb-meta.hh:111
struct @1060 hb_addressof
#define hb_is_trivially_copy_assignable(T)
Definition: hb-meta.hh:374
hb_conditional< hb_is_arithmetic< T >::value, hb_bool_constant<(T) 0<(T) -1 >, hb_false_type > hb_is_unsigned
Definition: hb-meta.hh:264
static T(hb_declval< >())
#define HB_FUNCOBJ(x)
Definition: hb-meta.hh:75
#define hb_is_trivially_copy_constructible(T)
Definition: hb-meta.hh:361
#define hb_is_reference(T)
Definition: hb-meta.hh:115
#define hb_prioritize
Definition: hb-meta.hh:73
const T hb_add_const
Definition: hb-meta.hh:103
auto _hb_try_add_lvalue_reference(hb_priority< 1 >) -> hb_type_identity< T & >
typename hb_match_reference< T >::type hb_remove_reference
Definition: hb-meta.hh:108
#define HB_AUTO_RETURN(E)
Definition: hb-meta.hh:68
decltype(_hb_try_add_pointer< T >(hb_priority< 16 >())) hb_add_pointer
Definition: hb-meta.hh:121
#define hb_is_arithmetic(T)
Definition: hb-meta.hh:253
auto _hb_try_add_pointer(hb_priority< 1 >) -> hb_type_identity< hb_remove_reference< T > * >
static constexpr T && hb_forward(hb_remove_reference< T > &t)
Definition: hb-meta.hh:177
hb_conditional< hb_is_arithmetic< T >::value, hb_bool_constant<(T) -1<(T) 0 >, hb_false_type > hb_is_signed
Definition: hb-meta.hh:259
#define hb_is_same(T, T2)
Definition: hb-meta.hh:63
struct @1062 hb_ref
auto _hb_try_add_rvalue_reference(hb_priority< 1 >) -> hb_type_identity< T && >
#define hb_is_integral(T)
Definition: hb-meta.hh:238
bool operator!=(const String &a, const String &b)
Compare two Strings for inequality.
Definition: string.hh:758
bool operator==(const String &a, const String &b)
Compares two strings for equality.
Definition: string.hh:739
Head type
Definition: hb-meta.hh:44
void type
Definition: hb-meta.hh:41
static auto impl(hb_priority< 1 >) -> decltype(impl2((hb_declval< T >())))
static constexpr bool either_void
Definition: hb-meta.hh:143
static hb_false_type impl(hb_priority< 0 >)
static constexpr bool both_void
Definition: hb-meta.hh:144
static hb_true_type impl2(hb_conditional< to_void, int, To >)
static constexpr bool from_void
Definition: hb-meta.hh:141
static constexpr bool to_void
Definition: hb-meta.hh:142
bool operator!=(const hb_reference_wrapper &o) const
Definition: hb-meta.hh:206
bool operator==(const hb_reference_wrapper &o) const
Definition: hb-meta.hh:205
Definition: dvips.h:235
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)
#define U(a)
Definition: twiddle.h:1
Definition: obx.h:51