34 #ifndef _CHAR_TRAITS_H
35 #define _CHAR_TRAITS_H 1
37 #pragma GCC system_header
43 #ifndef _GLIBCXX_ALWAYS_INLINE
44 # define _GLIBCXX_ALWAYS_INLINE inline __attribute__((__always_inline__))
47 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
49 _GLIBCXX_BEGIN_NAMESPACE_VERSION
61 template<
typename _CharT>
64 typedef unsigned long int_type;
67 typedef std::mbstate_t state_type;
86 template<
typename _CharT>
89 typedef _CharT char_type;
90 typedef typename _Char_types<_CharT>::int_type int_type;
92 typedef typename _Char_types<_CharT>::off_type off_type;
93 typedef typename _Char_types<_CharT>::state_type state_type;
95 static _GLIBCXX14_CONSTEXPR
void
96 assign(char_type& __c1,
const char_type& __c2)
99 static _GLIBCXX_CONSTEXPR
bool
100 eq(
const char_type& __c1,
const char_type& __c2)
101 {
return __c1 == __c2; }
103 static _GLIBCXX_CONSTEXPR
bool
104 lt(
const char_type& __c1,
const char_type& __c2)
105 {
return __c1 < __c2; }
107 static _GLIBCXX14_CONSTEXPR
int
108 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n);
110 static _GLIBCXX14_CONSTEXPR std::size_t
111 length(
const char_type* __s);
113 static _GLIBCXX14_CONSTEXPR
const char_type*
114 find(
const char_type* __s, std::size_t __n,
const char_type& __a);
116 static _GLIBCXX20_CONSTEXPR char_type*
117 move(char_type* __s1,
const char_type* __s2, std::size_t __n);
119 static _GLIBCXX20_CONSTEXPR char_type*
120 copy(char_type* __s1,
const char_type* __s2, std::size_t __n);
122 static _GLIBCXX20_CONSTEXPR char_type*
123 assign(char_type* __s, std::size_t __n, char_type __a);
125 static _GLIBCXX_CONSTEXPR char_type
126 to_char_type(
const int_type& __c)
127 {
return static_cast<char_type
>(__c); }
129 static _GLIBCXX_CONSTEXPR int_type
130 to_int_type(
const char_type& __c)
131 {
return static_cast<int_type
>(__c); }
133 static _GLIBCXX_CONSTEXPR
bool
134 eq_int_type(
const int_type& __c1,
const int_type& __c2)
135 {
return __c1 == __c2; }
137 static _GLIBCXX_CONSTEXPR int_type
139 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
141 static _GLIBCXX_CONSTEXPR int_type
142 not_eof(
const int_type& __c)
143 {
return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
146 template<
typename _CharT>
147 _GLIBCXX14_CONSTEXPR
int
149 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n)
151 for (std::size_t __i = 0; __i < __n; ++__i)
152 if (lt(__s1[__i], __s2[__i]))
154 else if (lt(__s2[__i], __s1[__i]))
159 template<
typename _CharT>
160 _GLIBCXX14_CONSTEXPR std::size_t
161 char_traits<_CharT>::
162 length(
const char_type* __p)
165 while (!eq(__p[__i], char_type()))
170 template<
typename _CharT>
171 _GLIBCXX14_CONSTEXPR
const typename char_traits<_CharT>::char_type*
172 char_traits<_CharT>::
173 find(
const char_type* __s, std::size_t __n,
const char_type& __a)
175 for (std::size_t __i = 0; __i < __n; ++__i)
176 if (eq(__s[__i], __a))
181 template<
typename _CharT>
183 typename char_traits<_CharT>::char_type*
184 char_traits<_CharT>::
185 move(char_type* __s1,
const char_type* __s2, std::size_t __n)
189 #ifdef __cpp_lib_is_constant_evaluated
190 if (std::is_constant_evaluated())
192 if (__s1 > __s2 && __s1 < __s2 + __n)
195 std::copy(__s2, __s2 + __n, __s1);
199 return static_cast<_CharT*
>(__builtin_memmove(__s1, __s2,
200 __n *
sizeof(char_type)));
203 template<
typename _CharT>
205 typename char_traits<_CharT>::char_type*
206 char_traits<_CharT>::
207 copy(char_type* __s1,
const char_type* __s2, std::size_t __n)
210 std::copy(__s2, __s2 + __n, __s1);
214 template<
typename _CharT>
216 typename char_traits<_CharT>::char_type*
217 char_traits<_CharT>::
218 assign(char_type* __s, std::size_t __n, char_type __a)
225 _GLIBCXX_END_NAMESPACE_VERSION
228 namespace std _GLIBCXX_VISIBILITY(default)
230 _GLIBCXX_BEGIN_NAMESPACE_VERSION
232 #if __cplusplus >= 201703L
233 #define __cpp_lib_constexpr_char_traits 201611
242 template<
typename _CharT>
243 static _GLIBCXX_ALWAYS_INLINE constexpr
bool
244 __constant_string_p(
const _CharT* __s)
246 #ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
249 return __builtin_is_constant_evaluated();
251 while (__builtin_constant_p(*__s) && *__s)
253 return __builtin_constant_p(*__s);
265 template<
typename _CharT>
266 static _GLIBCXX_ALWAYS_INLINE constexpr
bool
267 __constant_char_array_p(
const _CharT* __a,
size_t __n)
269 #ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
273 return __builtin_is_constant_evaluated();
276 while (__i < __n && __builtin_constant_p(__a[__i]))
296 template<
class _CharT>
305 typedef char char_type;
306 typedef int int_type;
309 typedef mbstate_t state_type;
311 static _GLIBCXX17_CONSTEXPR
void
312 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
315 static _GLIBCXX_CONSTEXPR
bool
316 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
317 {
return __c1 == __c2; }
319 static _GLIBCXX_CONSTEXPR
bool
320 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
323 return (
static_cast<unsigned char>(__c1)
324 <
static_cast<unsigned char>(__c2));
327 static _GLIBCXX17_CONSTEXPR
int
328 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
332 #if __cplusplus >= 201703L
333 if (__builtin_constant_p(__n)
334 && __constant_char_array_p(__s1, __n)
335 && __constant_char_array_p(__s2, __n))
338 return __builtin_memcmp(__s1, __s2, __n);
341 static _GLIBCXX17_CONSTEXPR
size_t
342 length(
const char_type* __s)
344 #if __cplusplus >= 201703L
345 if (__constant_string_p(__s))
348 return __builtin_strlen(__s);
351 static _GLIBCXX17_CONSTEXPR
const char_type*
352 find(
const char_type* __s,
size_t __n,
const char_type& __a)
356 #if __cplusplus >= 201703L
357 if (__builtin_constant_p(__n)
358 && __builtin_constant_p(__a)
359 && __constant_char_array_p(__s, __n))
362 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
365 static _GLIBCXX20_CONSTEXPR char_type*
366 move(char_type* __s1,
const char_type* __s2,
size_t __n)
370 #ifdef __cpp_lib_is_constant_evaluated
371 if (std::is_constant_evaluated())
374 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
377 static _GLIBCXX20_CONSTEXPR char_type*
378 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
382 #ifdef __cpp_lib_is_constant_evaluated
383 if (std::is_constant_evaluated())
386 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
389 static _GLIBCXX20_CONSTEXPR char_type*
390 assign(char_type* __s,
size_t __n, char_type __a)
394 #ifdef __cpp_lib_is_constant_evaluated
395 if (std::is_constant_evaluated())
398 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
401 static _GLIBCXX_CONSTEXPR char_type
402 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
403 {
return static_cast<char_type
>(__c); }
407 static _GLIBCXX_CONSTEXPR int_type
408 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
409 {
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
411 static _GLIBCXX_CONSTEXPR
bool
412 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
413 {
return __c1 == __c2; }
415 static _GLIBCXX_CONSTEXPR int_type
416 eof() _GLIBCXX_NOEXCEPT
417 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
419 static _GLIBCXX_CONSTEXPR int_type
420 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
421 {
return (__c == eof()) ? 0 : __c; }
425 #ifdef _GLIBCXX_USE_WCHAR_T
430 typedef wchar_t char_type;
431 typedef wint_t int_type;
434 typedef mbstate_t state_type;
436 static _GLIBCXX17_CONSTEXPR
void
437 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
440 static _GLIBCXX_CONSTEXPR
bool
441 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
442 {
return __c1 == __c2; }
444 static _GLIBCXX_CONSTEXPR
bool
445 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
446 {
return __c1 < __c2; }
448 static _GLIBCXX17_CONSTEXPR
int
449 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
453 #if __cplusplus >= 201703L
454 if (__builtin_constant_p(__n)
455 && __constant_char_array_p(__s1, __n)
456 && __constant_char_array_p(__s2, __n))
459 return wmemcmp(__s1, __s2, __n);
462 static _GLIBCXX17_CONSTEXPR
size_t
463 length(
const char_type* __s)
465 #if __cplusplus >= 201703L
466 if (__constant_string_p(__s))
472 static _GLIBCXX17_CONSTEXPR
const char_type*
473 find(
const char_type* __s,
size_t __n,
const char_type& __a)
477 #if __cplusplus >= 201703L
478 if (__builtin_constant_p(__n)
479 && __builtin_constant_p(__a)
480 && __constant_char_array_p(__s, __n))
483 return wmemchr(__s, __a, __n);
486 static _GLIBCXX20_CONSTEXPR char_type*
487 move(char_type* __s1,
const char_type* __s2,
size_t __n)
491 #ifdef __cpp_lib_is_constant_evaluated
492 if (std::is_constant_evaluated())
495 return wmemmove(__s1, __s2, __n);
498 static _GLIBCXX20_CONSTEXPR char_type*
499 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
503 #ifdef __cpp_lib_is_constant_evaluated
504 if (std::is_constant_evaluated())
507 return wmemcpy(__s1, __s2, __n);
510 static _GLIBCXX20_CONSTEXPR char_type*
511 assign(char_type* __s,
size_t __n, char_type __a)
515 #ifdef __cpp_lib_is_constant_evaluated
516 if (std::is_constant_evaluated())
519 return wmemset(__s, __a, __n);
522 static _GLIBCXX_CONSTEXPR char_type
523 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
524 {
return char_type(__c); }
526 static _GLIBCXX_CONSTEXPR int_type
527 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
528 {
return int_type(__c); }
530 static _GLIBCXX_CONSTEXPR
bool
531 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
532 {
return __c1 == __c2; }
534 static _GLIBCXX_CONSTEXPR int_type
535 eof() _GLIBCXX_NOEXCEPT
536 {
return static_cast<int_type
>(WEOF); }
538 static _GLIBCXX_CONSTEXPR int_type
539 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
540 {
return eq_int_type(__c, eof()) ? 0 : __c; }
542 #endif //_GLIBCXX_USE_WCHAR_T
544 #ifdef _GLIBCXX_USE_CHAR8_T
548 typedef char8_t char_type;
549 typedef unsigned int int_type;
550 typedef u8streampos pos_type;
552 typedef mbstate_t state_type;
554 static _GLIBCXX17_CONSTEXPR
void
555 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
558 static _GLIBCXX_CONSTEXPR
bool
559 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
560 {
return __c1 == __c2; }
562 static _GLIBCXX_CONSTEXPR
bool
563 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
564 {
return __c1 < __c2; }
566 static _GLIBCXX17_CONSTEXPR
int
567 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
571 #if __cplusplus > 201402
572 if (__builtin_constant_p(__n)
573 && __constant_char_array_p(__s1, __n)
574 && __constant_char_array_p(__s2, __n))
577 return __builtin_memcmp(__s1, __s2, __n);
580 static _GLIBCXX17_CONSTEXPR
size_t
581 length(
const char_type* __s)
583 #if __cplusplus > 201402
584 if (__constant_string_p(__s))
588 while (!eq(__s[__i], char_type()))
593 static _GLIBCXX17_CONSTEXPR
const char_type*
594 find(
const char_type* __s,
size_t __n,
const char_type& __a)
598 #if __cplusplus > 201402
599 if (__builtin_constant_p(__n)
600 && __builtin_constant_p(__a)
601 && __constant_char_array_p(__s, __n))
604 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
607 static _GLIBCXX20_CONSTEXPR char_type*
608 move(char_type* __s1,
const char_type* __s2,
size_t __n)
612 #ifdef __cpp_lib_is_constant_evaluated
613 if (std::is_constant_evaluated())
616 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
619 static _GLIBCXX20_CONSTEXPR char_type*
620 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
624 #ifdef __cpp_lib_is_constant_evaluated
625 if (std::is_constant_evaluated())
628 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
631 static _GLIBCXX20_CONSTEXPR char_type*
632 assign(char_type* __s,
size_t __n, char_type __a)
636 #ifdef __cpp_lib_is_constant_evaluated
637 if (std::is_constant_evaluated())
640 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
643 static _GLIBCXX_CONSTEXPR char_type
644 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
645 {
return char_type(__c); }
647 static _GLIBCXX_CONSTEXPR int_type
648 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
649 {
return int_type(__c); }
651 static _GLIBCXX_CONSTEXPR
bool
652 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
653 {
return __c1 == __c2; }
655 static _GLIBCXX_CONSTEXPR int_type
656 eof() _GLIBCXX_NOEXCEPT
657 {
return static_cast<int_type
>(-1); }
659 static _GLIBCXX_CONSTEXPR int_type
660 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
661 {
return eq_int_type(__c, eof()) ? 0 : __c; }
663 #endif //_GLIBCXX_USE_CHAR8_T
665 _GLIBCXX_END_NAMESPACE_VERSION
668 #if __cplusplus >= 201103L
672 namespace std _GLIBCXX_VISIBILITY(default)
674 _GLIBCXX_BEGIN_NAMESPACE_VERSION
677 struct char_traits<char16_t>
679 typedef char16_t char_type;
680 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
681 typedef uint_least16_t int_type;
682 #elif defined __UINT_LEAST16_TYPE__
683 typedef __UINT_LEAST16_TYPE__ int_type;
685 typedef make_unsigned<char16_t>::type int_type;
689 typedef mbstate_t state_type;
691 static _GLIBCXX17_CONSTEXPR
void
692 assign(char_type& __c1,
const char_type& __c2) noexcept
695 static constexpr
bool
696 eq(
const char_type& __c1,
const char_type& __c2) noexcept
697 {
return __c1 == __c2; }
699 static constexpr
bool
700 lt(
const char_type& __c1,
const char_type& __c2) noexcept
701 {
return __c1 < __c2; }
703 static _GLIBCXX17_CONSTEXPR
int
704 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
706 for (
size_t __i = 0; __i < __n; ++__i)
707 if (lt(__s1[__i], __s2[__i]))
709 else if (lt(__s2[__i], __s1[__i]))
714 static _GLIBCXX17_CONSTEXPR
size_t
715 length(
const char_type* __s)
718 while (!eq(__s[__i], char_type()))
723 static _GLIBCXX17_CONSTEXPR
const char_type*
724 find(
const char_type* __s,
size_t __n,
const char_type& __a)
726 for (
size_t __i = 0; __i < __n; ++__i)
727 if (eq(__s[__i], __a))
732 static _GLIBCXX20_CONSTEXPR char_type*
733 move(char_type* __s1,
const char_type* __s2,
size_t __n)
737 #ifdef __cpp_lib_is_constant_evaluated
738 if (std::is_constant_evaluated())
741 return (
static_cast<char_type*
>
742 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
745 static _GLIBCXX20_CONSTEXPR char_type*
746 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
750 #ifdef __cpp_lib_is_constant_evaluated
751 if (std::is_constant_evaluated())
754 return (
static_cast<char_type*
>
755 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
758 static _GLIBCXX20_CONSTEXPR char_type*
759 assign(char_type* __s,
size_t __n, char_type __a)
761 for (
size_t __i = 0; __i < __n; ++__i)
762 assign(__s[__i], __a);
766 static constexpr char_type
767 to_char_type(
const int_type& __c) noexcept
768 {
return char_type(__c); }
770 static constexpr int_type
771 to_int_type(
const char_type& __c) noexcept
772 {
return __c == eof() ? int_type(0xfffd) : int_type(__c); }
774 static constexpr
bool
775 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
776 {
return __c1 == __c2; }
778 static constexpr int_type
780 {
return static_cast<int_type
>(-1); }
782 static constexpr int_type
783 not_eof(
const int_type& __c) noexcept
784 {
return eq_int_type(__c, eof()) ? 0 : __c; }
788 struct char_traits<char32_t>
790 typedef char32_t char_type;
791 #ifdef _GLIBCXX_USE_C99_STDINT_TR1
792 typedef uint_least32_t int_type;
793 #elif defined __UINT_LEAST32_TYPE__
794 typedef __UINT_LEAST32_TYPE__ int_type;
796 typedef make_unsigned<char32_t>::type int_type;
800 typedef mbstate_t state_type;
802 static _GLIBCXX17_CONSTEXPR
void
803 assign(char_type& __c1,
const char_type& __c2) noexcept
806 static constexpr
bool
807 eq(
const char_type& __c1,
const char_type& __c2) noexcept
808 {
return __c1 == __c2; }
810 static constexpr
bool
811 lt(
const char_type& __c1,
const char_type& __c2) noexcept
812 {
return __c1 < __c2; }
814 static _GLIBCXX17_CONSTEXPR
int
815 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
817 for (
size_t __i = 0; __i < __n; ++__i)
818 if (lt(__s1[__i], __s2[__i]))
820 else if (lt(__s2[__i], __s1[__i]))
825 static _GLIBCXX17_CONSTEXPR
size_t
826 length(
const char_type* __s)
829 while (!eq(__s[__i], char_type()))
834 static _GLIBCXX17_CONSTEXPR
const char_type*
835 find(
const char_type* __s,
size_t __n,
const char_type& __a)
837 for (
size_t __i = 0; __i < __n; ++__i)
838 if (eq(__s[__i], __a))
843 static _GLIBCXX20_CONSTEXPR char_type*
844 move(char_type* __s1,
const char_type* __s2,
size_t __n)
848 #ifdef __cpp_lib_is_constant_evaluated
849 if (std::is_constant_evaluated())
852 return (
static_cast<char_type*
>
853 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
856 static _GLIBCXX20_CONSTEXPR char_type*
857 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
861 #ifdef __cpp_lib_is_constant_evaluated
862 if (std::is_constant_evaluated())
865 return (
static_cast<char_type*
>
866 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
869 static _GLIBCXX20_CONSTEXPR char_type*
870 assign(char_type* __s,
size_t __n, char_type __a)
872 for (
size_t __i = 0; __i < __n; ++__i)
873 assign(__s[__i], __a);
877 static constexpr char_type
878 to_char_type(
const int_type& __c) noexcept
879 {
return char_type(__c); }
881 static constexpr int_type
882 to_int_type(
const char_type& __c) noexcept
883 {
return int_type(__c); }
885 static constexpr
bool
886 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
887 {
return __c1 == __c2; }
889 static constexpr int_type
891 {
return static_cast<int_type
>(-1); }
893 static constexpr int_type
894 not_eof(
const int_type& __c) noexcept
895 {
return eq_int_type(__c, eof()) ? 0 : __c; }
898 _GLIBCXX_END_NAMESPACE_VERSION
903 #endif // _CHAR_TRAITS_H