YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
type_op.hpp
浏览该文件的文档.
1 /*
2  © 2011-2014 FrankHB.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #ifndef YB_INC_ystdex_type_op_hpp_
29 #define YB_INC_ystdex_type_op_hpp_ 1
30 
31 #include "../ydef.h" // for <type_traits> and std::declval;
32 
33 namespace ystdex
34 {
35 
36 #if 0
37 using std::tr1::add_reference;
38 
39 using std::tr1::has_nothrow_assign;
40 using std::tr1::has_nothrow_constructor;
41 using std::tr1::has_nothrow_copy;
42 using std::tr1::has_trivial_assign;
43 using std::tr1::has_trivial_constructor;
44 using std::tr1::has_trivial_copy;
45 using std::tr1::has_trivial_destructor;
46 #endif
47 
48 using std::integral_constant;
49 using std::true_type;
50 using std::false_type;
51 
52 using std::is_void;
53 using std::is_integral;
54 using std::is_floating_point;
55 using std::is_array;
56 using std::is_pointer;
57 using std::is_lvalue_reference;
58 using std::is_rvalue_reference;
59 using std::is_member_object_pointer;
60 using std::is_member_function_pointer;
61 using std::is_enum;
62 using std::is_class;
63 using std::is_union;
64 using std::is_function;
65 
66 using std::is_reference;
67 using std::is_arithmetic;
68 using std::is_fundamental;
69 using std::is_object;
70 using std::is_scalar;
71 using std::is_compound;
72 using std::is_member_pointer;
73 
74 using std::is_const;
75 using std::is_volatile;
76 using std::is_trivial;
77 // using std::is_trivially_copyable;
78 using std::is_standard_layout;
79 using std::is_pod;
80 using std::is_literal_type;
81 using std::is_empty;
82 using std::is_polymorphic;
83 using std::is_abstract;
84 
85 using std::is_signed;
86 using std::is_unsigned;
87 
88 using std::is_constructible;
89 #if 0
90 using std::is_default_constructible;
91 using std::is_copy_constructible;
92 using std::is_move_constructible;
93 
94 using std::is_assignable;
95 using std::is_copy_assignable;
96 using std::is_move_assignable;
97 
98 using std::is_destructible;
99 
100 using std::is_trivially_constructible;
101 using std::is_trivially_default_constructible;
102 using std::is_trivially_copy_constructible;
103 using std::is_trivially_move_constructible;
104 
105 using std::is_trivially_assignable;
106 using std::is_trivially_copy_assignable;
107 using std::is_trivially_move_assignable;
108 using std::is_trivially_destructible;
109 
110 using std::is_nothrow_constructible;
111 using std::is_nothrow_default_constructible;
112 using std::is_nothrow_copy_constructible;
113 using std::is_nothrow_move_constructible;
114 
115 using std::is_nothrow_assignable;
116 using std::is_nothrow_copy_assignable;
117 using std::is_nothrow_move_assignable;
118 
119 using std::is_nothrow_destructible;
120 #endif
121 using std::has_virtual_destructor;
122 
123 using std::alignment_of;
124 using std::rank;
125 using std::extent;
126 
127 using std::is_same;
128 using std::is_base_of;
129 using std::is_convertible;
130 
131 using std::remove_const;
132 using std::remove_volatile;
133 using std::remove_cv;
134 using std::add_const;
135 using std::add_volatile;
136 using std::add_cv;
137 
138 using std::remove_reference;
139 using std::add_lvalue_reference;
140 using std::add_rvalue_reference;
141 
142 using std::make_signed;
143 using std::make_unsigned;
144 
145 using std::remove_extent;
146 using std::remove_all_extents;
147 
148 using std::remove_pointer;
149 using std::add_pointer;
150 
151 using std::aligned_storage;
152 //using std::aligned_union;
153 using std::decay;
154 using std::enable_if;
155 using std::conditional;
156 using std::common_type;
158 using std::underlying_type;
159 using std::result_of;
160 
161 
213 
215 template<typename _type>
216 using remove_const_t = typename remove_const<_type>::type;
217 
218 template<typename _type>
219 using remove_volatile_t = typename remove_volatile<_type>::type;
220 
221 template<typename _type>
222 using remove_cv_t = typename remove_cv<_type>::type;
223 
224 template<typename _type>
225 using add_const_t = typename add_const<_type>::type;
226 
227 template<typename _type>
228 using add_volatile_t = typename add_volatile<_type>::type;
229 
230 template<typename _type>
231 using add_cv_t = typename add_cv<_type>::type;
232 
233 template<typename _type>
234 using remove_reference_t = typename remove_reference<_type>::type;
235 
236 template<typename _type>
237 using add_lvalue_reference_t = typename add_lvalue_reference<_type>::type;
238 
239 template<typename _type>
240 using add_rvalue_reference_t = typename add_rvalue_reference<_type>::type;
241 
242 template<typename _type>
243 using make_signed_t = typename make_signed<_type>::type;
244 
245 template<typename _type>
246 using make_unsigned_t = typename make_unsigned<_type>::type;
247 
248 template<typename _type>
249 using remove_extent_t = typename remove_extent<_type>::type;
250 
251 template<typename _type>
252 using remove_all_extents_t = typename remove_all_extents<_type>::type;
253 
254 template<typename _type>
255 using remove_pointer_t = typename remove_pointer<_type>::type;
256 
257 template<typename _type>
258 using add_pointer_t = typename add_pointer<_type>::type;
259 
260 template<size_t _vLen,
261  size_t _vAlign = yalignof(typename aligned_storage<_vLen>::type)>
262 using aligned_storage_t = typename aligned_storage<_vLen, _vAlign>::type;
264 
266 
267 //template<size_t _vLen, typename... _types>
268 //using aligned_union_t = typename aligned_union<_vLen, _types...>::type;
269 
270 template<typename _type>
271 using decay_t = typename decay<_type>::type;
272 
273 template<bool _bCond, typename _type = void>
274 using enable_if_t = typename enable_if<_bCond, _type>::type;
275 
276 template<bool _bCond, typename _type, typename _type2>
277 using conditional_t = typename conditional<_bCond, _type, _type2>::type;
278 
279 template<typename... _types>
280 using common_type_t = typename common_type<_types...>::type;
281 
282 template<typename _type>
283 using underlying_type_t = typename underlying_type<_type>::type;
284 
285 template<typename _type>
286 using result_of_t = typename result_of<_type>::type;
288 
289 
290 
298 template<typename _type>
299 struct is_returnable : integral_constant<bool, !is_array<_type>::value
300  && !is_abstract<_type>::value && !is_function<_type>::value>
301 {};
302 
303 
309 template<typename _type>
311  : integral_constant<bool, !is_same<decay_t<_type>, _type>::value>
312 {};
313 
314 
320 template<typename _type>
321 struct is_class_pointer : integral_constant<bool, is_pointer<_type>::value
322  && is_class<remove_pointer_t<_type>>::value>
323 {};
324 
325 
331 template<typename _type>
332 struct is_lvalue_class_reference : integral_constant<bool, !is_lvalue_reference<
333  _type>::value && is_class<remove_reference_t<_type>>::value>
334 {};
335 
336 
343 template<typename _type>
344 struct is_rvalue_class_reference : integral_constant<bool, !is_lvalue_reference<
345  _type>::value && is_class<typename remove_reference<_type>::type>::value>
346 {};
347 
348 
355 template<typename _type>
356 struct is_pod_struct : integral_constant<bool,
357  is_pod<_type>::value && is_class<_type>::value>
358 {};
359 
360 
367 template<typename _type>
368 struct is_pod_union : integral_constant<bool,
369  is_pod<_type>::value && is_union<_type>::value>
370 {};
371 
372 
378 template<typename _tFrom, typename _tTo>
379 struct is_covariant : is_convertible<_tFrom, _tTo>
380 {};
381 
382 
388 template<typename _tFrom, typename _tTo>
389 struct is_contravariant : is_convertible<_tTo, _tFrom>
390 {};
391 
392 
393 namespace details
394 {
395 
396 #ifdef YB_IMPL_GNUCPP
397 # if YB_IMPL_GNUCPP >= 40600
398 # pragma GCC diagnostic push
399 # pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
400 # else
401 # pragma GCC system_header
402 //临时处理:关闭所有警告。
403 /*
404 关闭编译警告:(C++ only) Ambiguous virtual bases. ,
405 参见 http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html 。
406 */
407 # endif
408 #endif
409 
410 
416 #define YB_HAS_MEMBER(_n) \
417  template<class _type> \
418  struct has_mem_##_n \
419  { \
420  private: \
421  template<typename _type2> \
422  static std::true_type \
423  test(ystdex::empty_base<typename _type2::_n>*); \
424  template<typename _type2> \
425  static std::false_type \
426  test(...); \
427  \
428  public: \
429  static yconstexpr bool value = decltype(test<_type>(nullptr))::value; \
430  };
431 
432 
434 #if !YB_IMPL_MSCPP
435 
441 #endif
442 
443 
448 #define YB_TYPE_OP_TEST_2(_n, _expr) \
449  template<typename _type1, typename _type2> \
450  struct _n \
451  { \
452  private: \
453  template<typename _type> \
454  static std::true_type \
455  test(ystdex::enable_if_t<(_expr), int>); \
456  template<typename> \
457  static std::false_type \
458  test(...); \
459  \
460  public: \
461  static yconstexpr bool value = decltype(test<_type1>(0))::value; \
462  };
463 
464 
470 YB_TYPE_OP_TEST_2(have_equality_operator, (is_convertible<decltype(std::declval<
471  _type>() == std::declval<_type2>()), bool>::value))
472 
473 
474 YB_TYPE_OP_TEST_2(has_subscription, !is_void<decltype(std::declval<_type>()[
476  std::declval<_type2>()])>::value)
477 
478 
479 #if YB_IMPL_GNUCPP && YB_IMPL_GNUCPP >= 40600
480 //# pragma GCC diagnostic warning "-Wctor-dtor-privacy"
481 # pragma GCC diagnostic pop
482 #endif
483 
484 
488 template<class _type>
490 {
491  static_assert(std::is_class<_type>::value,
492  "Non-class type found @ ystdex::has_nonempty_virtual_base;");
493 
494 private:
495  struct A : _type
496  {
498  ~A()
499  {}
500  };
501  struct B : _type
502  {
504  ~B()
505  {}
506  };
507  struct C : A, B
508  {
510  ~C()
511  {}
512  };
513 
514 public:
515  static yconstexpr bool value = sizeof(C) < sizeof(A) + sizeof(B);
516 };
517 
518 
522 template<class _type1, class _type2>
524 {
525  static_assert(std::is_class<_type1>::value
526  && std::is_class<_type2>::value,
527  "Non-class type found @ ystdex::has_common_nonempty_virtual_base;");
528 
529 private:
530  struct A : virtual _type1
531  {
533  ~A()
534  {}
535  };
536 
537 #ifdef YB_IMPL_GNUCPP
538 # if YB_IMPL_GNUCPP >= 40600
539 # pragma GCC diagnostic push
540 # pragma GCC diagnostic ignored "-Wextra"
541 # else
542 # pragma GCC system_header
543 # endif
544 #endif
545 
546  struct B : virtual _type2
547  {
549  ~B()
550  {}
551  };
552  struct C : A, B
553  {
555  ~C()
556  {}
557  };
558 
559 #if YB_IMPL_GNUCPP && YB_IMPL_GNUCPP >= 40600
560 //# pragma GCC diagnostic warning "-Wextra"
561 # pragma GCC diagnostic pop
562 #endif
563 
564 public:
565  static yconstexpr bool value = sizeof(C) < sizeof(A) + sizeof(B);
566 };
567 
568 } // namespace details;
569 
570 
572 #if !YB_IMPL_MSCPP
573 
578 template<class _type>
579 struct has_mem_value : std::integral_constant<bool,
580  details::has_mem_value<remove_cv_t<_type>>::value>
581 {};
582 #endif
583 
584 
590 template<typename _type1, typename _type2>
591 struct has_subscription : details::has_subscription<_type1, _type2>
592 {};
593 
594 
600 template<typename _type1, typename _type2>
601 struct has_equality_operator : integral_constant<bool,
602  details::have_equality_operator<_type1, _type2>::value>
603 {};
604 
605 
611 template<class _type>
612 struct has_nonempty_virtual_base : integral_constant<bool,
613  details::have_nonempty_virtual_base<_type>::value>
614 {};
615 
616 
622 template<class _type1, class _type2>
623 struct has_common_nonempty_virtual_base : integral_constant<bool,
624  details::have_common_nonempty_virtual_base<_type1, _type2>::value>
625 {};
626 
627 
642 template<typename _type>
643 struct identity
644 {
645  using type = _type;
646 };
647 
648 
656 template<typename _type>
658 {
660 };
661 
663 template<typename _type>
666 
667 
674 template<typename _type>
675 struct remove_rp
676 {
678 };
679 
680 
686 template<typename _type>
688 {
690 };
691 
692 
700 template<typename _type>
702 {
704 };
705 
706 
715 template<typename _type>
717 {
718 private:
720 
721 public:
723  || is_array<value_type>::value, decay_t<_type>, _type>;
724 };
725 
726 
736 template<typename _type>
738 {
739  using type = typename array_decay<_type>::type;
740 };
741 
742 template<typename _type>
743 struct array_ref_decay<_type&>
744 {
745  using type = typename array_decay<_type>::type;
746  using reference = type&;
747 };
748 
749 template<typename _type>
750 struct array_ref_decay<_type&&>
751 {
752  using type = typename array_decay<_type>::type;
753  using reference = type&&;
754 };
756 
757 
764 template<class _tClass, typename _tParam, typename _type = int>
767 
768 
781 template<size_t _vN>
782 struct n_tag
783 {
784  using type = n_tag<_vN - 1>;
785 };
786 
787 template<>
788 struct n_tag<0>
789 {
790  using type = void;
791 };
793 
799 
805 
806 } // namespace ystdex;
807 
808 #endif
809 
typename make_unsigned< _type >::type make_unsigned_t
Definition: type_op.hpp:246
判断指定类型是否是 POD union 。
Definition: type_op.hpp:368
#define YB_HAS_MEMBER(_n)
测试包含指定名称的嵌套成员。
Definition: type_op.hpp:416
判断指定类型是否是指向类类型对象的指针。
Definition: type_op.hpp:321
#define YB_TYPE_OP_TEST_2(_n, _expr)
测试包含指定的 2 个类型的表达式是否合式。
Definition: type_op.hpp:448
remove_cv_t< remove_reference_t< _type >> type
Definition: type_op.hpp:659
typename add_pointer< _type >::type add_pointer_t
Definition: type_op.hpp:258
typename add_lvalue_reference< _type >::type add_lvalue_reference_t
Definition: type_op.hpp:237
typename remove_reference< _type >::type remove_reference_t
Definition: type_op.hpp:234
typename result_of< _type >::type result_of_t
Definition: type_op.hpp:286
typename conditional< _bCond, _type, _type2 >::type conditional_t
Definition: type_op.hpp:277
typename underlying_type< _type >::type underlying_type_t
Definition: type_op.hpp:283
判断指定类型是否是 POD struct 。
Definition: type_op.hpp:356
typename remove_extent< _type >::type remove_extent_t
Definition: type_op.hpp:249
typename remove_volatile< _type >::type remove_volatile_t
Definition: type_op.hpp:219
typename decay< _type >::type decay_t
Definition: type_op.hpp:271
typename add_rvalue_reference< _type >::type add_rvalue_reference_t
Definition: type_op.hpp:240
typename remove_pointer< _type >::type remove_pointer_t
Definition: type_op.hpp:255
恒等元函数。
Definition: type_op.hpp:643
移除可能被 cv-qualifier 修饰的引用和指针类型。
Definition: type_op.hpp:687
typename remove_all_extents< _type >::type remove_all_extents_t
Definition: type_op.hpp:252
typename add_volatile< _type >::type add_volatile_t
Definition: type_op.hpp:228
判断指定类型是否有非空虚基类。
Definition: type_op.hpp:612
判断指定类型是否是右值类类型引用。
Definition: type_op.hpp:344
typename remove_rcv< _type >::type remove_rcv_t
Definition: type_op.hpp:664
判断指定类型之间是否协变。
Definition: type_op.hpp:379
remove_pointer_t< remove_reference_t< _type >> type
Definition: type_op.hpp:677
typename make_signed< _type >::type make_signed_t
Definition: type_op.hpp:243
判断是否存在合式的结果可转换为 bool 类型的 == 操作符接受指定类型的表达式。
Definition: type_op.hpp:601
typename aligned_storage< _vLen, _vAlign >::type aligned_storage_t
Definition: type_op.hpp:262
判断是否可被退化。
Definition: type_op.hpp:310
#define yalignof(_type)
指定特定类型的对齐。
Definition: ydef.h:442
数组类型退化。
Definition: type_op.hpp:701
typename remove_cv< _type >::type remove_cv_t
Definition: type_op.hpp:222
typename array_decay< _type >::type type
Definition: type_op.hpp:745
typename array_decay< _type >::type type
Definition: type_op.hpp:739
enable_if_t<!is_same< _tClass &, remove_rcv_t< _tParam > & >::value, _type > exclude_self_ctor_t
移除选择类类型的特定重载避免构造模板和复制/转移构造函数冲突。
Definition: type_op.hpp:766
typename array_decay< _type >::type type
Definition: type_op.hpp:752
判断指定类型是否可作为返回值类型。
Definition: type_op.hpp:299
conditional_t< is_function< value_type >::value||is_array< value_type >::value, decay_t< _type >, _type > type
Definition: type_op.hpp:723
remove_reference_t< _type > value_type
Definition: type_op.hpp:719
判断指定类型之间是否逆变。
Definition: type_op.hpp:389
判断指定的两个类类型是否有非空虚基类。
Definition: type_op.hpp:623
移除指针和引用类型。
Definition: type_op.hpp:675
保持修饰符的类型退化。
Definition: type_op.hpp:716
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
数组及数组引用类型退化。
Definition: type_op.hpp:737
remove_cv_t< typename remove_rp< _type >::type > type
Definition: type_op.hpp:689
判断 _type 是否包含 value 成员。
Definition: type_op.hpp:579
typename add_cv< _type >::type add_cv_t
Definition: type_op.hpp:231
conditional_t< is_array< _type >::value, decay_t< _type >, _type > type
Definition: type_op.hpp:703
自然数标记。
Definition: type_op.hpp:782
typename enable_if< _bCond, _type >::type enable_if_t
Definition: type_op.hpp:274
typename remove_const< _type >::type remove_const_t
ISO C++ 1y 兼容类型操作别名。
Definition: type_op.hpp:216
移除可能被 cv-qualifier 修饰的引用类型。
Definition: type_op.hpp:657
typename common_type< _types...>::type common_type_t
Definition: type_op.hpp:280
判断指定类型是否是左值类类型引用。
Definition: type_op.hpp:332
typename add_const< _type >::type add_const_t
Definition: type_op.hpp:225