32 #ifndef _CPP_TYPE_TRAITS_H
33 #define _CPP_TYPE_TRAITS_H 1
35 #ifdef _GLIBCXX_SYSHDR
36 #pragma GCC system_header
41 #if __glibcxx_type_trait_variable_templates
45 #pragma GCC diagnostic push
46 #pragma GCC diagnostic ignored "-Wlong-long"
78 namespace std _GLIBCXX_VISIBILITY(default)
80 _GLIBCXX_BEGIN_NAMESPACE_VERSION
82 struct __true_type { };
83 struct __false_type { };
87 {
typedef __false_type __type; };
90 struct __truth_type<true>
91 {
typedef __true_type __type; };
95 template<
class _Sp,
class _Tp>
98 enum { __value = bool(_Sp::__value) || bool(_Tp::__value) };
99 typedef typename __truth_type<__value>::__type __type;
103 template<
typename,
typename>
106 enum { __value = 0 };
107 typedef __false_type __type;
110 template<
typename _Tp>
111 struct __are_same<_Tp, _Tp>
113 enum { __value = 1 };
114 typedef __true_type __type;
120 template<
typename _Tp>
123 enum { __value = 0 };
124 typedef __false_type __type;
130 struct __is_integer<bool>
132 enum { __value = 1 };
133 typedef __true_type __type;
137 struct __is_integer<char>
139 enum { __value = 1 };
140 typedef __true_type __type;
144 struct __is_integer<signed char>
146 enum { __value = 1 };
147 typedef __true_type __type;
151 struct __is_integer<unsigned char>
153 enum { __value = 1 };
154 typedef __true_type __type;
157 # ifdef __WCHAR_TYPE__
159 struct __is_integer<wchar_t>
161 enum { __value = 1 };
162 typedef __true_type __type;
166 #ifdef _GLIBCXX_USE_CHAR8_T
168 struct __is_integer<char8_t>
170 enum { __value = 1 };
171 typedef __true_type __type;
175 #if __cplusplus >= 201103L
177 struct __is_integer<char16_t>
179 enum { __value = 1 };
180 typedef __true_type __type;
184 struct __is_integer<char32_t>
186 enum { __value = 1 };
187 typedef __true_type __type;
192 struct __is_integer<short>
194 enum { __value = 1 };
195 typedef __true_type __type;
199 struct __is_integer<unsigned short>
201 enum { __value = 1 };
202 typedef __true_type __type;
206 struct __is_integer<int>
208 enum { __value = 1 };
209 typedef __true_type __type;
213 struct __is_integer<unsigned int>
215 enum { __value = 1 };
216 typedef __true_type __type;
220 struct __is_integer<long>
222 enum { __value = 1 };
223 typedef __true_type __type;
227 struct __is_integer<unsigned long>
229 enum { __value = 1 };
230 typedef __true_type __type;
234 struct __is_integer<long long>
236 enum { __value = 1 };
237 typedef __true_type __type;
241 struct __is_integer<unsigned long long>
243 enum { __value = 1 };
244 typedef __true_type __type;
247 #define __INT_N(TYPE) \
250 struct __is_integer<TYPE> \
252 enum { __value = 1 }; \
253 typedef __true_type __type; \
257 struct __is_integer<unsigned TYPE> \
259 enum { __value = 1 }; \
260 typedef __true_type __type; \
263 #ifdef __GLIBCXX_TYPE_INT_N_0
264 __INT_N(__GLIBCXX_TYPE_INT_N_0)
266 #ifdef __GLIBCXX_TYPE_INT_N_1
267 __INT_N(__GLIBCXX_TYPE_INT_N_1)
269 #ifdef __GLIBCXX_TYPE_INT_N_2
270 __INT_N(__GLIBCXX_TYPE_INT_N_2)
272 #ifdef __GLIBCXX_TYPE_INT_N_3
273 __INT_N(__GLIBCXX_TYPE_INT_N_3)
281 template<
typename _Tp>
284 enum { __value = 0 };
285 typedef __false_type __type;
290 struct __is_floating<float>
292 enum { __value = 1 };
293 typedef __true_type __type;
297 struct __is_floating<double>
299 enum { __value = 1 };
300 typedef __true_type __type;
304 struct __is_floating<long double>
306 enum { __value = 1 };
307 typedef __true_type __type;
310 #ifdef __STDCPP_FLOAT16_T__
312 struct __is_floating<_Float16>
314 enum { __value = 1 };
315 typedef __true_type __type;
319 #ifdef __STDCPP_FLOAT32_T__
321 struct __is_floating<_Float32>
323 enum { __value = 1 };
324 typedef __true_type __type;
328 #ifdef __STDCPP_FLOAT64_T__
330 struct __is_floating<_Float64>
332 enum { __value = 1 };
333 typedef __true_type __type;
337 #ifdef __STDCPP_FLOAT128_T__
339 struct __is_floating<_Float128>
341 enum { __value = 1 };
342 typedef __true_type __type;
346 #ifdef __STDCPP_BFLOAT16_T__
348 struct __is_floating<
__gnu_cxx::__bfloat16_t>
350 enum { __value = 1 };
351 typedef __true_type __type;
358 template<
typename _Tp>
359 struct __is_arithmetic
360 :
public __traitor<__is_integer<_Tp>, __is_floating<_Tp> >
366 template<
typename _Tp>
369 enum { __value = 0 };
370 typedef __false_type __type;
374 struct __is_char<char>
376 enum { __value = 1 };
377 typedef __true_type __type;
380 #ifdef __WCHAR_TYPE__
382 struct __is_char<wchar_t>
384 enum { __value = 1 };
385 typedef __true_type __type;
389 template<
typename _Tp>
392 enum { __value = 0 };
393 typedef __false_type __type;
397 struct __is_byte<char>
399 enum { __value = 1 };
400 typedef __true_type __type;
404 struct __is_byte<signed char>
406 enum { __value = 1 };
407 typedef __true_type __type;
411 struct __is_byte<unsigned char>
413 enum { __value = 1 };
414 typedef __true_type __type;
417 #ifdef __glibcxx_byte
418 enum class byte : unsigned char;
421 struct __is_byte<byte>
423 enum { __value = 1 };
424 typedef __true_type __type;
428 #ifdef _GLIBCXX_USE_CHAR8_T
430 struct __is_byte<char8_t>
432 enum { __value = 1 };
433 typedef __true_type __type;
438 template<
typename _Tp>
439 struct __is_nonvolatile_trivially_copyable
441 enum { __value = __is_trivially_copyable(_Tp) };
447 template<
typename _Tp>
448 struct __is_nonvolatile_trivially_copyable<volatile _Tp>
450 enum { __value = 0 };
454 template<
typename _OutputIter,
typename _InputIter>
457 enum { __value = 0 };
461 template<
typename _Tp>
462 struct __memcpyable<_Tp*, _Tp*>
463 : __is_nonvolatile_trivially_copyable<_Tp>
467 template<
typename _Tp>
468 struct __memcpyable<_Tp*,
const _Tp*>
469 : __is_nonvolatile_trivially_copyable<_Tp>
472 template<
typename _Tp>
struct __memcpyable_integer;
477 template<
typename _Tp,
typename _Up>
478 struct __memcpyable<_Tp*, _Up*>
481 __value = __memcpyable_integer<_Tp>::__width != 0
482 && ((int)__memcpyable_integer<_Tp>::__width
483 == (
int)__memcpyable_integer<_Up>::__width)
488 template<
typename _Tp,
typename _Up>
489 struct __memcpyable<_Tp*,
const _Up*>
490 : __memcpyable<_Tp*, _Up*>
493 template<
typename _Tp>
494 struct __memcpyable_integer
497 __width = __is_integer<_Tp>::__value ? (
sizeof(_Tp) * __CHAR_BIT__) : 0
502 template<
typename _Tp>
503 struct __memcpyable_integer<volatile _Tp>
504 {
enum { __width = 0 }; };
507 #if defined __GLIBCXX_TYPE_INT_N_0 && __GLIBCXX_BITSIZE_INT_N_0 % __CHAR_BIT__
510 struct __memcpyable_integer<__GLIBCXX_TYPE_INT_N_0>
511 {
enum { __width = __GLIBCXX_BITSIZE_INT_N_0 }; };
514 struct __memcpyable_integer<unsigned __GLIBCXX_TYPE_INT_N_0>
515 {
enum { __width = __GLIBCXX_BITSIZE_INT_N_0 }; };
517 #if defined __GLIBCXX_TYPE_INT_N_1 && __GLIBCXX_BITSIZE_INT_N_1 % __CHAR_BIT__
520 struct __memcpyable_integer<__GLIBCXX_TYPE_INT_N_1>
521 {
enum { __width = __GLIBCXX_BITSIZE_INT_N_1 }; };
524 struct __memcpyable_integer<unsigned __GLIBCXX_TYPE_INT_N_1>
525 {
enum { __width = __GLIBCXX_BITSIZE_INT_N_1 }; };
527 #if defined __GLIBCXX_TYPE_INT_N_2 && __GLIBCXX_BITSIZE_INT_N_2 % __CHAR_BIT__
530 struct __memcpyable_integer<__GLIBCXX_TYPE_INT_N_2>
531 {
enum { __width = __GLIBCXX_BITSIZE_INT_N_2 }; };
534 struct __memcpyable_integer<unsigned __GLIBCXX_TYPE_INT_N_2>
535 {
enum { __width = __GLIBCXX_BITSIZE_INT_N_2 }; };
537 #if defined __GLIBCXX_TYPE_INT_N_3 && __GLIBCXX_BITSIZE_INT_N_3 % __CHAR_BIT__
540 struct __memcpyable_integer<__GLIBCXX_TYPE_INT_N_3>
541 {
enum { __width = __GLIBCXX_BITSIZE_INT_N_3 }; };
544 struct __memcpyable_integer<unsigned __GLIBCXX_TYPE_INT_N_3>
545 {
enum { __width = __GLIBCXX_BITSIZE_INT_N_3 }; };
548 #if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__
553 struct __memcpyable_integer<__int128> {
enum { __width = 128 }; };
556 struct __memcpyable_integer<unsigned __int128> {
enum { __width = 128 }; };
559 #if _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 && _GLIBCXX_LDOUBLE_IS_IEEE_BINARY64
561 struct __memcpyable<double*,
long double*> {
enum { __value =
true }; };
563 struct __memcpyable<long double*,
double*> {
enum { __value =
true }; };
566 #if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
568 struct __memcpyable<_Float32*,
float*> {
enum { __value =
true }; };
570 struct __memcpyable<float*, _Float32*> {
enum { __value =
true }; };
573 #if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
575 struct __memcpyable<_Float64*,
double*> {
enum { __value =
true }; };
577 struct __memcpyable<double*, _Float64*> {
enum { __value =
true }; };
580 #if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
582 struct __memcpyable<_Float128*,
long double*> {
enum { __value =
true }; };
584 struct __memcpyable<long double*, _Float128*> {
enum { __value =
true }; };
592 template<
typename _Iter1,
typename _Iter2>
595 enum { __value = 0 };
599 template<
typename _Tp>
600 struct __memcmpable<_Tp*, _Tp*>
601 : __is_nonvolatile_trivially_copyable<_Tp>
604 template<
typename _Tp>
605 struct __memcmpable<const _Tp*, _Tp*>
606 : __is_nonvolatile_trivially_copyable<_Tp>
609 template<
typename _Tp>
610 struct __memcmpable<_Tp*,
const _Tp*>
611 : __is_nonvolatile_trivially_copyable<_Tp>
620 template<
typename _Tp,
bool _TreatAsBytes =
621 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
622 __is_integer<_Tp>::__value
624 __is_byte<_Tp>::__value
627 struct __is_memcmp_ordered
629 static const bool __value = _Tp(-1) > _Tp(1);
632 template<
typename _Tp>
633 struct __is_memcmp_ordered<_Tp, false>
635 static const bool __value =
false;
639 template<
typename _Tp,
typename _Up,
bool = sizeof(_Tp) == sizeof(_Up)>
640 struct __is_memcmp_ordered_with
642 static const bool __value = __is_memcmp_ordered<_Tp>::__value
643 && __is_memcmp_ordered<_Up>::__value;
646 template<
typename _Tp,
typename _Up>
647 struct __is_memcmp_ordered_with<_Tp, _Up, false>
649 static const bool __value =
false;
652 #if __cplusplus >= 201703L
653 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
656 struct __is_memcmp_ordered<
std::byte, false>
657 {
static constexpr
bool __value =
true; };
662 struct __is_memcmp_ordered_with<
std::byte, std::byte, true>
663 {
static constexpr
bool __value =
true; };
665 template<
typename _Tp,
bool _SameSize>
666 struct __is_memcmp_ordered_with<_Tp,
std::byte, _SameSize>
667 {
static constexpr
bool __value =
false; };
669 template<
typename _Up,
bool _SameSize>
670 struct __is_memcmp_ordered_with<
std::byte, _Up, _SameSize>
671 {
static constexpr
bool __value =
false; };
674 #if __glibcxx_type_trait_variable_templates
675 template<
typename _ValT,
typename _Tp>
676 constexpr
bool __can_use_memchr_for_find
678 = __is_byte<_ValT>::__value
680 && (is_same_v<_Tp, _ValT> || is_integral_v<_Tp>);
686 template<
typename _Tp>
687 struct __is_move_iterator
689 enum { __value = 0 };
690 typedef __false_type __type;
695 template<
typename _Iterator>
698 __miter_base(_Iterator __it)
701 _GLIBCXX_END_NAMESPACE_VERSION
705 #pragma GCC diagnostic pop
ISO C++ entities toplevel namespace is std.
GNU extensions for public use.