29 #ifndef _GLIBCXX_TYPE_TRAITS
30 #define _GLIBCXX_TYPE_TRAITS 1
32 #pragma GCC system_header
34 #ifndef __GXX_EXPERIMENTAL_CXX0X__
38 #if defined(_GLIBCXX_INCLUDE_AS_TR1)
39 # error C++0x header cannot be included from TR1 header
44 #if defined(_GLIBCXX_INCLUDE_AS_CXX0X)
47 # define _GLIBCXX_INCLUDE_AS_CXX0X
48 # define _GLIBCXX_BEGIN_NAMESPACE_TR1
49 # define _GLIBCXX_END_NAMESPACE_TR1
53 # undef _GLIBCXX_END_NAMESPACE_TR1
54 # undef _GLIBCXX_BEGIN_NAMESPACE_TR1
55 # undef _GLIBCXX_INCLUDE_AS_CXX0X
71 template<
typename _Tp>
80 template<
typename _Tp>
87 template<
typename _Tp>
90 || is_rvalue_reference<_Tp>::value)>
96 template<
typename _Tp>
98 {
typedef _Tp type; };
100 template<
typename _Tp>
102 {
typedef _Tp type; };
104 template<
typename _Tp>
105 struct remove_reference<_Tp&&>
106 {
typedef _Tp type; };
108 template<
typename _Tp,
109 bool = !is_reference<_Tp>::value && !is_void<_Tp>::value,
110 bool = is_rvalue_reference<_Tp>::value>
111 struct __add_lvalue_reference_helper
112 {
typedef _Tp type; };
114 template<
typename _Tp>
115 struct __add_lvalue_reference_helper<_Tp, true, false>
116 {
typedef _Tp& type; };
118 template<
typename _Tp>
119 struct __add_lvalue_reference_helper<_Tp, false, true>
120 {
typedef typename remove_reference<_Tp>::type& type; };
123 template<
typename _Tp>
125 :
public __add_lvalue_reference_helper<_Tp>
128 template<
typename _Tp,
130 struct __add_rvalue_reference_helper
131 {
typedef _Tp type; };
133 template<
typename _Tp>
134 struct __add_rvalue_reference_helper<_Tp, true>
135 {
typedef _Tp&& type; };
138 template<
typename _Tp>
140 :
public __add_rvalue_reference_helper<_Tp>
145 template<
typename _Tp,
148 struct __is_signed_helper
151 template<
typename _Tp>
152 struct __is_signed_helper<_Tp, false, true>
155 template<
typename _Tp>
156 struct __is_signed_helper<_Tp, true, false>
157 :
public integral_constant<bool, _Tp(-1) < _Tp(0)>
161 template<typename _Tp>
163 : public integral_constant<bool, __is_signed_helper<_Tp>::value>
167 template<typename _Tp>
169 : public integral_constant<bool, (is_arithmetic<_Tp>::value
170 && !is_signed<_Tp>::value)>
176 template<typename _Tp>
178 : public integral_constant<bool, __is_pod(_Tp)>
182 template<typename _Tp>
183 struct has_trivial_default_constructor
184 : public integral_constant<bool, __has_trivial_constructor(_Tp)>
188 template<typename _Tp>
189 struct has_trivial_copy_constructor
190 : public integral_constant<bool, __has_trivial_copy(_Tp)>
194 template<typename _Tp>
195 struct has_trivial_assign
196 : public integral_constant<bool, __has_trivial_assign(_Tp)>
200 template<typename _Tp>
201 struct has_trivial_destructor
202 : public integral_constant<bool, __has_trivial_destructor(_Tp)>
206 template<typename _Tp>
207 struct has_nothrow_default_constructor
208 : public integral_constant<bool, __has_nothrow_constructor(_Tp)>
212 template<typename _Tp>
213 struct has_nothrow_copy_constructor
214 : public integral_constant<bool, __has_nothrow_copy(_Tp)>
218 template<typename _Tp>
219 struct has_nothrow_assign
220 : public integral_constant<bool, __has_nothrow_assign(_Tp)>
224 template<typename _Base, typename _Derived>
226 : public integral_constant<bool, __is_base_of(_Base, _Derived)>
230 template<typename _From, typename _To>
231 struct __is_convertible_simple
232 : public __sfinae_types
235 static __one __test(_To);
236 static __two __test(...);
237 static _From __makeFrom();
240 static const bool __value = sizeof(__test(__makeFrom())) == 1;
243 template<typename _Tp>
244 struct __is_int_or_cref
246 typedef typename remove_reference<_Tp>::type __rr_Tp;
247 static const bool __value = (is_integral<_Tp>::value
248 || (is_integral<__rr_Tp>::value
249 && is_const<__rr_Tp>::value
250 && !is_volatile<__rr_Tp>::value));
253 template<typename _From, typename _To,
254 bool = (is_void<_From>::value || is_void<_To>::value
255 || is_function<_To>::value || is_array<_To>::value
257 || (is_floating_point<typename
258 remove_reference<_From>::type>::value
259 && __is_int_or_cref<_To>::__value))>
260 struct __is_convertible_helper
263 static const bool __value = (__is_convertible_simple<typename
264 add_lvalue_reference<_From>::type,
268 template<typename _From, typename _To>
269 struct __is_convertible_helper<_From, _To, true>
270 { static const bool __value = (is_void<_To>::value
271 || (__is_int_or_cref<_To>::__value
272 && !is_void<_From>::value)); };
277 template<typename _From, typename _To>
278 struct is_convertible
279 : public integral_constant<bool,
280 __is_convertible_helper<_From, _To>::__value>
283 template<std::size_t _Len>
284 struct __aligned_storage_msa
288 unsigned char __data[_Len];
289 struct __attribute__((__aligned__)) { } __align;
303 template<std::size_t _Len, std::size_t _Align =
304 __alignof__(typename __aligned_storage_msa<_Len>::__type)>
305 struct aligned_storage
309 unsigned char __data[_Len];
310 struct __attribute__((__aligned__((_Align)))) { } __align;
318 template<bool, typename _Tp = void>
323 template<typename _Tp>
324 struct enable_if<true, _Tp>
325 { typedef _Tp type; };
331 template<bool _Cond, typename _Iftrue, typename _Iffalse>
333 { typedef _Iftrue type; };
336 template<typename _Iftrue, typename _Iffalse>
337 struct conditional<false, _Iftrue, _Iffalse>
338 { typedef _Iffalse type; };
343 template<typename _Up,
344 bool _IsArray = is_array<_Up>::value,
345 bool _IsFunction = is_function<_Up>::value>
346 struct __decay_selector;
349 template<typename _Up>
350 struct __decay_selector<_Up, false, false>
351 { typedef typename remove_cv<_Up>::type __type; };
353 template<typename _Up>
354 struct __decay_selector<_Up, true, false>
355 { typedef typename remove_extent<_Up>::type* __type; };
357 template<typename _Up>
358 struct __decay_selector<_Up, false, true>
359 { typedef typename add_pointer<_Up>::type __type; };
362 template<typename _Tp>
366 typedef typename remove_reference<_Tp>::type __remove_type;
369 typedef typename __decay_selector<__remove_type>::__type type;
374 template<typename _Unqualified, bool _IsConst, bool _IsVol>
375 struct __cv_selector;
377 template<typename _Unqualified>
378 struct __cv_selector<_Unqualified, false, false>
379 { typedef _Unqualified __type; };
381 template<typename _Unqualified>
382 struct __cv_selector<_Unqualified, false, true>
383 { typedef volatile _Unqualified __type; };
385 template<typename _Unqualified>
386 struct __cv_selector<_Unqualified, true, false>
387 { typedef const _Unqualified __type; };
389 template<typename _Unqualified>
390 struct __cv_selector<_Unqualified, true, true>
391 { typedef const volatile _Unqualified __type; };
393 template<typename _Qualified, typename _Unqualified,
394 bool _IsConst = is_const<_Qualified>::value,
395 bool _IsVol = is_volatile<_Qualified>::value>
396 struct __match_cv_qualifiers
399 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
402 typedef typename __match::__type __type;
407 template<typename _Tp>
408 struct __make_unsigned
409 { typedef _Tp __type; };
412 struct __make_unsigned<char>
413 { typedef unsigned char __type; };
416 struct __make_unsigned<signed char>
417 { typedef unsigned char __type; };
420 struct __make_unsigned<short>
421 { typedef unsigned short __type; };
424 struct __make_unsigned<int>
425 { typedef unsigned int __type; };
428 struct __make_unsigned<long>
429 { typedef unsigned long __type; };
432 struct __make_unsigned<long long>
433 { typedef unsigned long long __type; };
437 template<typename _Tp,
438 bool _IsInt = is_integral<_Tp>::value,
439 bool _IsEnum = is_enum<_Tp>::value>
440 struct __make_unsigned_selector;
442 template<typename _Tp>
443 struct __make_unsigned_selector<_Tp, true, false>
446 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
447 typedef typename __unsignedt::__type __unsigned_type;
448 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
451 typedef typename __cv_unsigned::__type __type;
454 template<typename _Tp>
455 struct __make_unsigned_selector<_Tp, false, true>
459 typedef unsigned char __smallest;
460 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
461 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
462 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
463 typedef conditional<__b2, unsigned int, unsigned long> __cond2;
464 typedef typename __cond2::type __cond2_type;
465 typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
466 typedef typename __cond1::type __cond1_type;
469 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
476 template<typename _Tp>
478 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
482 struct make_unsigned<bool>;
486 template<typename _Tp>
488 { typedef _Tp __type; };
491 struct __make_signed<char>
492 { typedef signed char __type; };
495 struct __make_signed<unsigned char>
496 { typedef signed char __type; };
499 struct __make_signed<unsigned short>
500 { typedef signed short __type; };
503 struct __make_signed<unsigned int>
504 { typedef signed int __type; };
507 struct __make_signed<unsigned long>
508 { typedef signed long __type; };
511 struct __make_signed<unsigned long long>
512 { typedef signed long long __type; };
516 template<typename _Tp,
517 bool _IsInt = is_integral<_Tp>::value,
518 bool _IsEnum = is_enum<_Tp>::value>
519 struct __make_signed_selector;
521 template<typename _Tp>
522 struct __make_signed_selector<_Tp, true, false>
525 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
526 typedef typename __signedt::__type __signed_type;
527 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
530 typedef typename __cv_signed::__type __type;
533 template<typename _Tp>
534 struct __make_signed_selector<_Tp, false, true>
538 typedef signed char __smallest;
539 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
540 static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
541 static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
542 typedef conditional<__b2, signed int, signed long> __cond2;
543 typedef typename __cond2::type __cond2_type;
544 typedef conditional<__b1, signed short, __cond2_type> __cond1;
545 typedef typename __cond1::type __cond1_type;
548 typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
555 template<typename _Tp>
557 { typedef typename __make_signed_selector<_Tp>::__type type; };
561 struct make_signed<bool>;
564 template<typename... _Tp>
567 template<typename _Tp>
568 struct common_type<_Tp>
570 static_assert(sizeof(_Tp) > 0, "must be complete type");
574 template<typename _Tp, typename _Up>
575 class common_type<_Tp, _Up>
577 static_assert(sizeof(_Tp) > 0, "must be complete type");
578 static_assert(sizeof(_Up) > 0, "must be complete type");
586 static bool __true_or_false();
589 typedef decltype(__true_or_false() ? __t() : __u()) type;
592 template<typename _Tp, typename _Up, typename... _Vp>
593 struct common_type<_Tp, _Up, _Vp...>
596 common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;