mn_typetraits.hpp
Go to the documentation of this file.
1 
18 #ifndef _MINLIB_TYPE_TRAITS_H_
19 #define _MINLIB_TYPE_TRAITS_H_
20 
21 #include "mn_config.hpp"
22 #include "mn_def.hpp"
23 
28 namespace mn {
29  template <typename T>
30  struct type_traits {
31  using value_type = T;
32  using const_type = const T;
33  using reference = T&;
34  using const_reference = const T&;
35  using pointer = T*;
36  using const_pointer = const T*;
37  };
38 
39  template <typename T>
40  struct type_traits<T&> {
41  using value_type = T;
42  using const_type = const T;
43  using reference = T&;
44  using const_reference = const T&;
45  using pointer = T*;
46  using const_pointer = const T*;
47  };
48 
49  template <typename T>
50  struct type_traits<const T> {
51  using value_type = T;
52  using const_type = const T;
53  using reference = T&;
54  using const_reference = const T&;
55  using pointer = T*;
56  using const_pointer = const T*;
57  };
58 
59  template <typename T>
60  struct type_traits<const T&> {
61  using value_type = T;
62  using const_type = const T;
63  using reference = T&;
64  using const_reference = const T&;
65  using pointer = T*;
66  using const_pointer = const T*;
67  };
68 
69  template <typename T>
70  struct type_traits<volatile T&> {
71  using value_type = T;
72  using const_type = const T;
73  using reference = T&;
74  using const_reference = const T&;
75  using pointer = T*;
76  using const_pointer = const T*;
77  };
78 
79  template <typename T>
80  struct type_traits<const volatile T&> {
81  using value_type = T;
82  using const_type = const T;
83  using reference = T&;
84  using const_reference = const T&;
85  using pointer = T*;
86  using const_pointer = const T*;
87  };
88 
89  template <typename T>
90  struct type_traits<T*> {
91  using value_type = T*;
92  using const_type = const T*;
93  using reference = T*&;
94  using const_reference = const T*&;
95  using pointer = T*;
96  using const_pointer = const T*;
97  };
98 
99  template <typename T, size_t N>
100  struct type_traits<T [N]> {
101  private:
102  typedef T array_type[N];
103  public:
104  using value_type = T*;
105  using const_type = const T*;
106  using reference = array_type&;
107  using const_reference = const array_type&;
108  using pointer = T*;
109  using const_pointer = const T*;
110  };
111 
112  template <typename T, size_t N>
113  struct type_traits<const T [N]> {
114  private:
115  typedef const T array_type[N];
116  public:
117  using value_type = const T*;
118  using const_type = const T*;
119  using reference = array_type&;
120  using const_reference = const array_type&;
121  using pointer = T*;
122  using const_pointer = const T*;
123  };
124 
125  template<class T, T v> struct integral_constant {
126  enum { value = v };
127  };
128 
131 
132  template<typename>
133  struct is_const : public false_type { };
134 
135  template<typename T>
136  struct is_const<T const> : public true_type { };
137 
139  template<typename>
140  struct is_volatile : public false_type { };
141 
142  template<typename T>
143  struct is_volatile<T volatile> : public true_type { };
144 
145 
146 
148  template<typename T>
149  struct is_empty : public integral_constant<bool, __is_empty(T)> { };
150 
151 
152  template<typename T>
153  struct is_enum : public integral_constant<bool, __is_enum(T)> { };
154 
155  template<typename T>
156  struct is_union : public integral_constant<bool, __is_union(T)> { };
157 
158  template<typename T>
159  struct is_class : public integral_constant<bool, __is_class(T)> { };
160 
161  template<typename>
162  struct is_function;
163 
164  template<typename>
165  struct is_function : public false_type { };
166 
167  template<typename T, typename... Args>
168  struct is_function<T(Args...)> : public true_type { };
169 
170  template<typename T, typename... Args>
171  struct is_function<T(Args...) &> : public true_type { };
172 
173  template<typename T, typename... Args>
174  struct is_function<T(Args...) &&> : public true_type { };
175 
176  template<typename T, typename... Args>
177  struct is_function<T(Args......)> : public true_type { };
178 
179  template<typename T, typename... Args>
180  struct is_function<T(Args......) &> : public true_type { };
181 
182  template<typename T, typename... Args>
183  struct is_function<T(Args......) &&> : public true_type { };
184 
185  template<typename T, typename... Args>
186  struct is_function<T(Args...) const> : public true_type { };
187 
188  template<typename T, typename... Args>
189  struct is_function<T(Args...) const &> : public true_type { };
190 
191  template<typename T, typename... Args>
192  struct is_function<T(Args...) const &&> : public true_type { };
193 
194  template<typename T, typename... Args>
195  struct is_function<T(Args......) const> : public true_type { };
196 
197  template<typename T, typename... Args>
198  struct is_function<T(Args......) const &> : public true_type { };
199 
200  template<typename T, typename... Args>
201  struct is_function<T(Args......) const &&> : public true_type { };
202 
203  template<typename T, typename... Args>
204  struct is_function<T(Args...) volatile> : public true_type { };
205 
206  template<typename T, typename... Args>
207  struct is_function<T(Args...) volatile &> : public true_type { };
208 
209  template<typename T, typename... Args>
210  struct is_function<T(Args...) volatile &&> : public true_type { };
211 
212  template<typename T, typename... Args>
213  struct is_function<T(Args......) volatile> : public true_type { };
214 
215  template<typename T, typename... Args>
216  struct is_function<T(Args......) volatile &> : public true_type { };
217 
218  template<typename T, typename... Args>
219  struct is_function<T(Args......) volatile &&> : public true_type { };
220 
221  template<typename T, typename... Args>
222  struct is_function<T(Args...) const volatile> : public true_type { };
223 
224  template<typename T, typename... Args>
225  struct is_function<T(Args...) const volatile &> : public true_type { };
226 
227  template<typename T, typename... Args>
228  struct is_function<T(Args...) const volatile &&> : public true_type { };
229 
230  template<typename T, typename... Args>
231  struct is_function<T(Args......) const volatile> : public true_type { };
232 
233  template<typename T, typename... Args>
234  struct is_function<T(Args......) const volatile &> : public true_type { };
235 
236  template<typename T, typename... Args>
237  struct is_function<T(Args......) const volatile &&> : public true_type { };
238 
239  template<typename T>
240  struct is_abstract : public integral_constant<bool, __is_abstract(T)> { };
241 
242  template<typename T>
243  struct is_polymorphic : public integral_constant<bool, __is_polymorphic(T)> { };
244 
245  template<typename T>
246  struct is_literal_type : public integral_constant<bool, __is_literal_type(T)> { };
247 
248  template<typename T>
249  struct is_pod : public integral_constant<bool, __is_pod(T)> { };
250 
252  template<typename T>
253  struct is_trivial : public integral_constant<bool, __is_trivial(T)> { };
254 
255  // is_trivially_copyable
256  template<typename T>
257  struct is_trivially_copyable : public integral_constant<bool, __is_trivially_copyable(T)> { };
258 
260  template<typename T>
261  struct is_standard_layout : public integral_constant<bool, __is_standard_layout(T)> { };
262 
263  template<typename T>
264  struct is_bind_expression : public false_type { };
265 
266  template<typename T>
267  struct is_placeholder : public integral_constant<int, 0> { };
268 
269 
270 
271 
272 
273  template<typename T>
274  struct is_integral : public integral_constant<bool, false> { };
275 
276  template<class T>
277  struct is_integral<const T> : public is_integral<T> { };
278 
279  template<class T>
280  struct is_integral<volatile T> : public is_integral<T> { };
281 
282  template<class T>
283  struct is_integral<const volatile T> : public is_integral<T> { };
284 
285 
286 
287  template<typename T>
288  struct is_rational : public integral_constant<bool, false> { };
289 
290  template<class T>
291  struct is_rational<const T> : public is_rational<T> { };
292 
293  template<class T>
294  struct is_rational<volatile T> : public is_rational<T> { };
295 
296  template<class T>
297  struct is_rational<const volatile T> : public is_rational<T> { };
298 
299  template<typename T>
300  struct is_void : public integral_constant<bool, false> { };
301 
302  template<class T>
303  struct is_void<const T> : public is_void<T> { };
304 
305  template<class T>
306  struct is_void<volatile T> : public is_void<T> { };
307 
308  template<class T>
309  struct is_void<const volatile T> : public is_void<T> { };
310 
311  template<typename T>
312  struct is_floating_point : public integral_constant<bool, false> { };
313 
314  template<>
315  struct is_floating_point<float> : public integral_constant<bool, true> { };
316 
317  template<>
318  struct is_floating_point<double> : public integral_constant<bool, true> { };
319 
320  template <>
321  struct is_floating_point<long double> : public integral_constant<bool, true> { };
322 
323  template <typename T>
324  struct is_floating_point<const T> : is_floating_point<T> {};
325 
326  template <typename T>
327  struct is_floating_point<volatile T> : is_floating_point<T> {};
328 
329  template <typename T>
330  struct is_floating_point<const volatile T> : is_floating_point<T> {};
331 
333  template<typename>
334  struct is_lvalue_reference : public false_type { };
335 
336  template<typename T>
337  struct is_lvalue_reference<T&> : public true_type { };
338 
339 
341  template<typename>
342  struct is_rvalue_reference : public false_type { };
343 
344  template<typename T>
345  struct is_rvalue_reference<T&&> : public true_type { };
346 
347  template<typename T>
348  struct is_pointer
349  : public integral_constant<bool, false> { };
350 
351  template<typename T>
352  struct is_pointer<T*>
353  : public integral_constant<bool, true> { };
354 
355  template<typename T>
357  : public integral_constant<bool, is_integral<T>::value || is_rational<T>::value> { };
358 
359  template<typename T>
361  : public integral_constant<bool, is_fundamental<T>::value | is_pointer<T>::value | is_pod<T>::value> { };
362 
363  template<typename T>
365  : public integral_constant<bool, is_fundamental<T>::value | is_pointer<T>::value | is_pod<T>::value> { };
366 
367  template<typename T>
369  : public integral_constant<bool, is_fundamental<T>::value | is_pointer<T>::value | is_pod<T>::value> { };
370 
371  template<typename T>
373  : public integral_constant<bool, is_fundamental<T>::value || is_pointer<T>::value || is_pod<T>::value> { };
374 
375  template<typename T>
377  : public integral_constant<bool, is_lvalue_reference<T>::value | is_rvalue_reference<T>::value> { };
378 
380  template<typename T>
382  : public integral_constant< bool, !(is_integral<T>::value | is_floating_point<T>::value) > { };
383 
385  template<typename T>
386  struct is_object
387  : public integral_constant< bool, ! (is_function<T>::value | is_reference<T>::value |
388  is_void<T>::value) > { };
389 
391  template <typename T>
392  struct is_signed : false_type {};
393 
394  template <>
395  struct is_signed<char> : integral_constant<bool, (char(255) < 0)> {};
396 
397  template <>
398  struct is_signed<signed char> : true_type {};
399 
400  template <>
401  struct is_signed<short> : true_type {};
402 
403  template <>
404  struct is_signed<int> : true_type {};
405 
406  template <>
407  struct is_signed<long> : true_type {};
408 
409  template <>
410  struct is_signed<long long> : true_type {};
411 
412  template <>
413  struct is_signed<float> : true_type {};
414 
415  template <>
416  struct is_signed<double> : true_type {};
417 
418  template <>
419  struct is_signed<long double> : true_type {};
420 
421  template <typename T>
422  struct is_signed<const T> : is_signed<T> {};
423 
424  template <typename T>
425  struct is_signed<volatile T> : is_signed<T> {};
426 
427  template <typename T>
428  struct is_signed<const volatile T> : is_signed<T> {};
429 
430 
432  template <typename T>
433  struct is_unsigned : false_type {};
434 
435  template <>
436  struct is_unsigned<bool> : true_type {};
437 
438  template <>
439  struct is_unsigned<char> : integral_constant<bool, (char(255) > 0)> {};
440 
441  template <>
442  struct is_unsigned<unsigned char> : true_type {};
443 
444  template <>
445  struct is_unsigned<unsigned short> : true_type {};
446 
447  template <>
448  struct is_unsigned<unsigned int> : true_type {};
449 
450  template <>
451  struct is_unsigned<unsigned long> : true_type {};
452 
453  template <>
454  struct is_unsigned<unsigned long long> : true_type {};
455 
456  template <typename T>
457  struct is_unsigned<const T> : is_unsigned<T> {};
458 
459  template <typename T>
460  struct is_unsigned<volatile T> : is_unsigned<T> {};
461 
462  template <typename T>
463  struct is_unsigned<const volatile T> : is_unsigned<T> {};
464 
465  template<typename>
467 
468 
469 
471  template<typename T>
472  struct is_compound
473  : public integral_constant<bool, !is_fundamental<T>::value> { };
474 
475 
476  template<typename T>
477  struct has_cheap_compare : public integral_constant<bool, has_trivial_copy<T>::value && sizeof(T) <= 4 > { };
478 
479 
480  template<size_t size, size_t align = alignof(void *)>
481  struct aligned_storage {
482  struct type { alignas(align) unsigned char data[size]; };
483  };
484 
485  template<size_t size, size_t align = alignof(void *)>
486  using aligned_storage_t = typename aligned_storage<size, align>::type;
487 
488 
489 
490  #define MN_INTEGRAL(T) template<> \
491  struct is_integral<T> : public integral_constant<bool, true> { };
492 
493  #define MN_RATIONAL(T) template<> \
494  struct is_rational<T> : public integral_constant<bool, true> { };
495 
496  #define MN_VOIDTYPE(T) template<> \
497  struct is_void<T> : public integral_constant<bool, true> { };
498 
499  MN_INTEGRAL(char);
500  MN_INTEGRAL(unsigned char);
501  MN_INTEGRAL(short);
502  MN_INTEGRAL(unsigned short);
503  MN_INTEGRAL(int);
504  MN_INTEGRAL(unsigned int);
505  MN_INTEGRAL(long);
506  MN_INTEGRAL(unsigned long);
507  MN_INTEGRAL(wchar_t);
508  MN_INTEGRAL(bool);
509 
510  MN_VOIDTYPE(void);
511  MN_VOIDTYPE(const void);
512  MN_VOIDTYPE(volatile void );
513  MN_VOIDTYPE(const volatile void );
514 
515  MN_RATIONAL(float);
516  MN_RATIONAL(double);
517  MN_RATIONAL(long double);
518 }
519 
520 
521 #endif
struct mn::memory::detail::ptr_difference T
Definition: mn_atomic_singleton.hpp:38
Definition: mn_allocator_typetraits.hpp:25
const T *& const_reference
Definition: mn_typetraits.hpp:94
T value_type
Definition: mn_typetraits.hpp:51
const T * const_pointer
Definition: mn_typetraits.hpp:96
const T & const_reference
Definition: mn_typetraits.hpp:34
T & reference
Definition: mn_typetraits.hpp:63
T * pointer
Definition: mn_typetraits.hpp:35
T & reference
Definition: mn_typetraits.hpp:73
const T * const_type
Definition: mn_typetraits.hpp:92
T * pointer
Definition: mn_typetraits.hpp:75
T value_type
Definition: mn_typetraits.hpp:71
T & reference
Definition: mn_typetraits.hpp:43
const T * const_pointer
Definition: mn_typetraits.hpp:86
const T * const_pointer
Definition: mn_typetraits.hpp:56
const T * const_pointer
Definition: mn_typetraits.hpp:76
const T & const_reference
Definition: mn_typetraits.hpp:44
T * pointer
Definition: mn_typetraits.hpp:65
const T * const_pointer
Definition: mn_typetraits.hpp:36
const T & const_reference
Definition: mn_typetraits.hpp:64
T value_type
Definition: mn_typetraits.hpp:61
const T const_type
Definition: mn_typetraits.hpp:82
T & reference
Definition: mn_typetraits.hpp:83
T * pointer
Definition: mn_typetraits.hpp:85
T value_type
Definition: mn_typetraits.hpp:41
T * pointer
Definition: mn_typetraits.hpp:45
const T * const_pointer
Definition: mn_typetraits.hpp:66
T *& reference
Definition: mn_typetraits.hpp:93
const T const_type
Definition: mn_typetraits.hpp:32
const T const_type
Definition: mn_typetraits.hpp:62
T value_type
Definition: mn_typetraits.hpp:81
T * pointer
Definition: mn_typetraits.hpp:95
T * pointer
Definition: mn_typetraits.hpp:55
T value_type
Definition: mn_typetraits.hpp:31
const T const_type
Definition: mn_typetraits.hpp:42
T * value_type
Definition: mn_typetraits.hpp:91
const T const_type
Definition: mn_typetraits.hpp:72
T & reference
Definition: mn_typetraits.hpp:53
const T & const_reference
Definition: mn_typetraits.hpp:84
const T & const_reference
Definition: mn_typetraits.hpp:54
const T const_type
Definition: mn_typetraits.hpp:52
T & reference
Definition: mn_typetraits.hpp:33
const T * const_pointer
Definition: mn_typetraits.hpp:46
const T & const_reference
Definition: mn_typetraits.hpp:74
Definition: mn_typetraits.hpp:466
Definition: mn_typetraits.hpp:30
Definition: mn_typetraits.hpp:369
Definition: mn_typetraits.hpp:361
Definition: mn_typetraits.hpp:365
Definition: mn_typetraits.hpp:373
Definition: mn_typetraits.hpp:125
@ value
Definition: mn_typetraits.hpp:126
Definition: mn_typetraits.hpp:240
is_arithmetic
Definition: mn_typetraits.hpp:382
Definition: mn_typetraits.hpp:264
Definition: mn_typetraits.hpp:159
is_compound
Definition: mn_typetraits.hpp:473
Definition: mn_typetraits.hpp:133
is_empty
Definition: mn_typetraits.hpp:149
Definition: mn_typetraits.hpp:153
Definition: mn_typetraits.hpp:312
Definition: mn_typetraits.hpp:165
Definition: mn_typetraits.hpp:357
Definition: mn_typetraits.hpp:274
Definition: mn_typetraits.hpp:246
is_lvalue_reference
Definition: mn_typetraits.hpp:334
is_object
Definition: mn_typetraits.hpp:388
Definition: mn_typetraits.hpp:267
Definition: mn_typetraits.hpp:249
Definition: mn_typetraits.hpp:349
Definition: mn_typetraits.hpp:243
Definition: mn_typetraits.hpp:288
Definition: mn_typetraits.hpp:377
is_rvalue_reference
Definition: mn_typetraits.hpp:342
is_signed
Definition: mn_typetraits.hpp:392
is_standard_layout
Definition: mn_typetraits.hpp:261
is_trivial
Definition: mn_typetraits.hpp:253
Definition: mn_typetraits.hpp:257
Definition: mn_typetraits.hpp:156
is_unsigned
Definition: mn_typetraits.hpp:433
Definition: mn_typetraits.hpp:300
is_volatile
Definition: mn_typetraits.hpp:140
array_type & reference
Definition: mn_typetraits.hpp:106
T * pointer
Definition: mn_typetraits.hpp:108
const T * const_pointer
Definition: mn_typetraits.hpp:109
const T * const_type
Definition: mn_typetraits.hpp:105
T * value_type
Definition: mn_typetraits.hpp:104
const array_type & const_reference
Definition: mn_typetraits.hpp:107
array_type & reference
Definition: mn_typetraits.hpp:119
T * pointer
Definition: mn_typetraits.hpp:121
const T * const_pointer
Definition: mn_typetraits.hpp:122
const T * value_type
Definition: mn_typetraits.hpp:117
const T * const_type
Definition: mn_typetraits.hpp:118
const array_type & const_reference
Definition: mn_typetraits.hpp:120