35#define _CHAR_TRAITS_H 1
37#pragma GCC system_header
42#if __cplusplus > 201703L
46#ifndef _GLIBCXX_ALWAYS_INLINE
47# define _GLIBCXX_ALWAYS_INLINE inline __attribute__((__always_inline__))
50namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
52_GLIBCXX_BEGIN_NAMESPACE_VERSION
64 template<
typename _CharT>
67 typedef unsigned long int_type;
70 typedef std::mbstate_t state_type;
89 template<
typename _CharT>
92 typedef _CharT char_type;
93 typedef typename _Char_types<_CharT>::int_type int_type;
95 typedef typename _Char_types<_CharT>::off_type off_type;
96 typedef typename _Char_types<_CharT>::state_type state_type;
97#if __cpp_lib_three_way_comparison
98 using comparison_category = std::strong_ordering;
101 static _GLIBCXX14_CONSTEXPR
void
102 assign(char_type& __c1,
const char_type& __c2)
105 static _GLIBCXX_CONSTEXPR
bool
106 eq(
const char_type& __c1,
const char_type& __c2)
107 {
return __c1 == __c2; }
109 static _GLIBCXX_CONSTEXPR
bool
110 lt(
const char_type& __c1,
const char_type& __c2)
111 {
return __c1 < __c2; }
113 static _GLIBCXX14_CONSTEXPR
int
114 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n);
116 static _GLIBCXX14_CONSTEXPR std::size_t
117 length(
const char_type* __s);
119 static _GLIBCXX14_CONSTEXPR
const char_type*
120 find(
const char_type* __s, std::size_t __n,
const char_type& __a);
122 static _GLIBCXX20_CONSTEXPR char_type*
123 move(char_type* __s1,
const char_type* __s2, std::size_t __n);
125 static _GLIBCXX20_CONSTEXPR char_type*
126 copy(char_type* __s1,
const char_type* __s2, std::size_t __n);
128 static _GLIBCXX20_CONSTEXPR char_type*
129 assign(char_type* __s, std::size_t __n, char_type __a);
131 static _GLIBCXX_CONSTEXPR char_type
132 to_char_type(
const int_type& __c)
133 {
return static_cast<char_type
>(__c); }
135 static _GLIBCXX_CONSTEXPR int_type
136 to_int_type(
const char_type& __c)
137 {
return static_cast<int_type
>(__c); }
139 static _GLIBCXX_CONSTEXPR
bool
140 eq_int_type(
const int_type& __c1,
const int_type& __c2)
141 {
return __c1 == __c2; }
143 static _GLIBCXX_CONSTEXPR int_type
145 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
147 static _GLIBCXX_CONSTEXPR int_type
148 not_eof(
const int_type& __c)
149 {
return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
152 template<
typename _CharT>
153 _GLIBCXX14_CONSTEXPR
int
155 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n)
157 for (std::size_t __i = 0; __i < __n; ++__i)
158 if (lt(__s1[__i], __s2[__i]))
160 else if (lt(__s2[__i], __s1[__i]))
165 template<
typename _CharT>
166 _GLIBCXX14_CONSTEXPR std::size_t
167 char_traits<_CharT>::
168 length(
const char_type* __p)
171 while (!eq(__p[__i], char_type()))
176 template<
typename _CharT>
177 _GLIBCXX14_CONSTEXPR
const typename char_traits<_CharT>::char_type*
178 char_traits<_CharT>::
179 find(
const char_type* __s, std::size_t __n,
const char_type& __a)
181 for (std::size_t __i = 0; __i < __n; ++__i)
182 if (eq(__s[__i], __a))
187 template<
typename _CharT>
189 typename char_traits<_CharT>::char_type*
190 char_traits<_CharT>::
191 move(char_type* __s1,
const char_type* __s2, std::size_t __n)
195#if __cpp_lib_is_constant_evaluated
196 if (std::is_constant_evaluated())
200#if __cpp_constexpr_dynamic_alloc
203 char_type* __tmp =
new char_type[__n];
204 copy(__tmp, __s2, __n);
205 copy(__s1, __tmp, __n);
208 const auto __end = __s2 + __n - 1;
209 bool __overlap =
false;
210 for (std::size_t __i = 0; __i < __n - 1; ++__i)
212 if (__s1 + __i == __end)
223 assign(__s1[__n], __s2[__n]);
228 copy(__s1, __s2, __n);
233 __builtin_memmove(__s1, __s2, __n *
sizeof(char_type));
237 template<
typename _CharT>
239 typename char_traits<_CharT>::char_type*
240 char_traits<_CharT>::
241 copy(char_type* __s1,
const char_type* __s2, std::size_t __n)
244 std::copy(__s2, __s2 + __n, __s1);
248 template<
typename _CharT>
250 typename char_traits<_CharT>::char_type*
251 char_traits<_CharT>::
252 assign(char_type* __s, std::size_t __n, char_type __a)
255 std::fill_n(__s, __n, __a);
259_GLIBCXX_END_NAMESPACE_VERSION
262namespace std _GLIBCXX_VISIBILITY(default)
264_GLIBCXX_BEGIN_NAMESPACE_VERSION
266#if __cplusplus >= 201703L
268#ifdef __cpp_lib_is_constant_evaluated
270# define __cpp_lib_constexpr_char_traits 201811L
273# define __cpp_lib_constexpr_char_traits 201611L
283 template<
typename _CharT>
284 _GLIBCXX_ALWAYS_INLINE
constexpr bool
287#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
290 return __builtin_is_constant_evaluated();
292 while (__builtin_constant_p(*__s) && *__s)
294 return __builtin_constant_p(*__s);
306 template<
typename _CharT>
307 _GLIBCXX_ALWAYS_INLINE
constexpr bool
310#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
314 return __builtin_is_constant_evaluated();
317 while (__i < __n && __builtin_constant_p(__a[__i]))
337 template<
class _CharT>
346 typedef char char_type;
347 typedef int int_type;
350 typedef mbstate_t state_type;
351#if __cpp_lib_three_way_comparison
352 using comparison_category = strong_ordering;
355 static _GLIBCXX17_CONSTEXPR
void
356 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
359 static _GLIBCXX_CONSTEXPR
bool
360 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
361 {
return __c1 == __c2; }
363 static _GLIBCXX_CONSTEXPR
bool
364 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
367 return (
static_cast<unsigned char>(__c1)
368 <
static_cast<unsigned char>(__c2));
371 static _GLIBCXX17_CONSTEXPR
int
372 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
376#if __cplusplus >= 201703L
377 if (__builtin_constant_p(__n)
381 for (
size_t __i = 0; __i < __n; ++__i)
382 if (lt(__s1[__i], __s2[__i]))
384 else if (lt(__s2[__i], __s1[__i]))
389 return __builtin_memcmp(__s1, __s2, __n);
392 static _GLIBCXX17_CONSTEXPR
size_t
393 length(
const char_type* __s)
395#if __cplusplus >= 201703L
399 return __builtin_strlen(__s);
402 static _GLIBCXX17_CONSTEXPR
const char_type*
403 find(
const char_type* __s,
size_t __n,
const char_type& __a)
407#if __cplusplus >= 201703L
408 if (__builtin_constant_p(__n)
409 && __builtin_constant_p(__a)
413 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
416 static _GLIBCXX20_CONSTEXPR char_type*
417 move(char_type* __s1,
const char_type* __s2,
size_t __n)
421#ifdef __cpp_lib_is_constant_evaluated
422 if (std::is_constant_evaluated())
425 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
428 static _GLIBCXX20_CONSTEXPR char_type*
429 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
433#ifdef __cpp_lib_is_constant_evaluated
434 if (std::is_constant_evaluated())
437 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
440 static _GLIBCXX20_CONSTEXPR char_type*
441 assign(char_type* __s,
size_t __n, char_type __a)
445#ifdef __cpp_lib_is_constant_evaluated
446 if (std::is_constant_evaluated())
449 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
452 static _GLIBCXX_CONSTEXPR char_type
453 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
454 {
return static_cast<char_type
>(__c); }
458 static _GLIBCXX_CONSTEXPR int_type
459 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
460 {
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
462 static _GLIBCXX_CONSTEXPR
bool
463 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
464 {
return __c1 == __c2; }
466 static _GLIBCXX_CONSTEXPR int_type
467 eof() _GLIBCXX_NOEXCEPT
468 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
470 static _GLIBCXX_CONSTEXPR int_type
471 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
472 {
return (__c == eof()) ? 0 : __c; }
476#ifdef _GLIBCXX_USE_WCHAR_T
481 typedef wchar_t char_type;
482 typedef wint_t int_type;
485 typedef mbstate_t state_type;
486#if __cpp_lib_three_way_comparison
487 using comparison_category = strong_ordering;
490 static _GLIBCXX17_CONSTEXPR
void
491 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
494 static _GLIBCXX_CONSTEXPR
bool
495 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
496 {
return __c1 == __c2; }
498 static _GLIBCXX_CONSTEXPR
bool
499 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
500 {
return __c1 < __c2; }
502 static _GLIBCXX17_CONSTEXPR
int
503 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
507#if __cplusplus >= 201703L
508 if (__builtin_constant_p(__n)
513 return wmemcmp(__s1, __s2, __n);
516 static _GLIBCXX17_CONSTEXPR
size_t
517 length(
const char_type* __s)
519#if __cplusplus >= 201703L
526 static _GLIBCXX17_CONSTEXPR
const char_type*
527 find(
const char_type* __s,
size_t __n,
const char_type& __a)
531#if __cplusplus >= 201703L
532 if (__builtin_constant_p(__n)
533 && __builtin_constant_p(__a)
537 return wmemchr(__s, __a, __n);
540 static _GLIBCXX20_CONSTEXPR char_type*
541 move(char_type* __s1,
const char_type* __s2,
size_t __n)
545#ifdef __cpp_lib_is_constant_evaluated
546 if (std::is_constant_evaluated())
549 return wmemmove(__s1, __s2, __n);
552 static _GLIBCXX20_CONSTEXPR char_type*
553 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
557#ifdef __cpp_lib_is_constant_evaluated
558 if (std::is_constant_evaluated())
561 return wmemcpy(__s1, __s2, __n);
564 static _GLIBCXX20_CONSTEXPR char_type*
565 assign(char_type* __s,
size_t __n, char_type __a)
569#ifdef __cpp_lib_is_constant_evaluated
570 if (std::is_constant_evaluated())
573 return wmemset(__s, __a, __n);
576 static _GLIBCXX_CONSTEXPR char_type
577 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
578 {
return char_type(__c); }
580 static _GLIBCXX_CONSTEXPR int_type
581 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
582 {
return int_type(__c); }
584 static _GLIBCXX_CONSTEXPR
bool
585 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
586 {
return __c1 == __c2; }
588 static _GLIBCXX_CONSTEXPR int_type
589 eof() _GLIBCXX_NOEXCEPT
590 {
return static_cast<int_type
>(WEOF); }
592 static _GLIBCXX_CONSTEXPR int_type
593 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
594 {
return eq_int_type(__c, eof()) ? 0 : __c; }
598#ifdef _GLIBCXX_USE_CHAR8_T
602 typedef char8_t char_type;
603 typedef unsigned int int_type;
604 typedef u8streampos pos_type;
606 typedef mbstate_t state_type;
607#if __cpp_lib_three_way_comparison
608 using comparison_category = strong_ordering;
611 static _GLIBCXX17_CONSTEXPR
void
612 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
615 static _GLIBCXX_CONSTEXPR
bool
616 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
617 {
return __c1 == __c2; }
619 static _GLIBCXX_CONSTEXPR
bool
620 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
621 {
return __c1 < __c2; }
623 static _GLIBCXX17_CONSTEXPR
int
624 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
628#if __cplusplus > 201402
629 if (__builtin_constant_p(__n)
634 return __builtin_memcmp(__s1, __s2, __n);
637 static _GLIBCXX17_CONSTEXPR
size_t
638 length(
const char_type* __s)
640#if __cplusplus > 201402
645 while (!eq(__s[__i], char_type()))
650 static _GLIBCXX17_CONSTEXPR
const char_type*
651 find(
const char_type* __s,
size_t __n,
const char_type& __a)
655#if __cplusplus > 201402
656 if (__builtin_constant_p(__n)
657 && __builtin_constant_p(__a)
661 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
664 static _GLIBCXX20_CONSTEXPR char_type*
665 move(char_type* __s1,
const char_type* __s2,
size_t __n)
669#ifdef __cpp_lib_is_constant_evaluated
670 if (std::is_constant_evaluated())
673 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
676 static _GLIBCXX20_CONSTEXPR char_type*
677 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
681#ifdef __cpp_lib_is_constant_evaluated
682 if (std::is_constant_evaluated())
685 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
688 static _GLIBCXX20_CONSTEXPR char_type*
689 assign(char_type* __s,
size_t __n, char_type __a)
693#ifdef __cpp_lib_is_constant_evaluated
694 if (std::is_constant_evaluated())
697 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
700 static _GLIBCXX_CONSTEXPR char_type
701 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
702 {
return char_type(__c); }
704 static _GLIBCXX_CONSTEXPR int_type
705 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
706 {
return int_type(__c); }
708 static _GLIBCXX_CONSTEXPR
bool
709 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
710 {
return __c1 == __c2; }
712 static _GLIBCXX_CONSTEXPR int_type
713 eof() _GLIBCXX_NOEXCEPT
714 {
return static_cast<int_type
>(-1); }
716 static _GLIBCXX_CONSTEXPR int_type
717 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
718 {
return eq_int_type(__c, eof()) ? 0 : __c; }
722_GLIBCXX_END_NAMESPACE_VERSION
725#if __cplusplus >= 201103L
729namespace std _GLIBCXX_VISIBILITY(default)
731_GLIBCXX_BEGIN_NAMESPACE_VERSION
734 struct char_traits<char16_t>
736 typedef char16_t char_type;
737#ifdef _GLIBCXX_USE_C99_STDINT_TR1
738 typedef uint_least16_t int_type;
739#elif defined __UINT_LEAST16_TYPE__
740 typedef __UINT_LEAST16_TYPE__ int_type;
742 typedef make_unsigned<char16_t>::type int_type;
746 typedef mbstate_t state_type;
747#if __cpp_lib_three_way_comparison
748 using comparison_category = strong_ordering;
751 static _GLIBCXX17_CONSTEXPR
void
752 assign(char_type& __c1,
const char_type& __c2)
noexcept
755 static constexpr bool
756 eq(
const char_type& __c1,
const char_type& __c2)
noexcept
757 {
return __c1 == __c2; }
759 static constexpr bool
760 lt(
const char_type& __c1,
const char_type& __c2)
noexcept
761 {
return __c1 < __c2; }
763 static _GLIBCXX17_CONSTEXPR
int
764 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
766 for (
size_t __i = 0; __i < __n; ++__i)
767 if (lt(__s1[__i], __s2[__i]))
769 else if (lt(__s2[__i], __s1[__i]))
774 static _GLIBCXX17_CONSTEXPR
size_t
775 length(
const char_type* __s)
778 while (!eq(__s[__i], char_type()))
783 static _GLIBCXX17_CONSTEXPR
const char_type*
784 find(
const char_type* __s,
size_t __n,
const char_type& __a)
786 for (
size_t __i = 0; __i < __n; ++__i)
787 if (eq(__s[__i], __a))
792 static _GLIBCXX20_CONSTEXPR char_type*
793 move(char_type* __s1,
const char_type* __s2,
size_t __n)
797#ifdef __cpp_lib_is_constant_evaluated
798 if (std::is_constant_evaluated())
801 return (
static_cast<char_type*
>
802 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
805 static _GLIBCXX20_CONSTEXPR char_type*
806 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
810#ifdef __cpp_lib_is_constant_evaluated
811 if (std::is_constant_evaluated())
814 return (
static_cast<char_type*
>
815 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
818 static _GLIBCXX20_CONSTEXPR char_type*
819 assign(char_type* __s,
size_t __n, char_type __a)
821 for (
size_t __i = 0; __i < __n; ++__i)
822 assign(__s[__i], __a);
826 static constexpr char_type
827 to_char_type(
const int_type& __c)
noexcept
828 {
return char_type(__c); }
830 static constexpr int_type
831 to_int_type(
const char_type& __c)
noexcept
832 {
return __c == eof() ? int_type(0xfffd) : int_type(__c); }
834 static constexpr bool
835 eq_int_type(
const int_type& __c1,
const int_type& __c2)
noexcept
836 {
return __c1 == __c2; }
838 static constexpr int_type
840 {
return static_cast<int_type
>(-1); }
842 static constexpr int_type
843 not_eof(
const int_type& __c)
noexcept
844 {
return eq_int_type(__c, eof()) ? 0 : __c; }
848 struct char_traits<char32_t>
850 typedef char32_t char_type;
851#ifdef _GLIBCXX_USE_C99_STDINT_TR1
852 typedef uint_least32_t int_type;
853#elif defined __UINT_LEAST32_TYPE__
854 typedef __UINT_LEAST32_TYPE__ int_type;
856 typedef make_unsigned<char32_t>::type int_type;
860 typedef mbstate_t state_type;
861#if __cpp_lib_three_way_comparison
862 using comparison_category = strong_ordering;
865 static _GLIBCXX17_CONSTEXPR
void
866 assign(char_type& __c1,
const char_type& __c2)
noexcept
869 static constexpr bool
870 eq(
const char_type& __c1,
const char_type& __c2)
noexcept
871 {
return __c1 == __c2; }
873 static constexpr bool
874 lt(
const char_type& __c1,
const char_type& __c2)
noexcept
875 {
return __c1 < __c2; }
877 static _GLIBCXX17_CONSTEXPR
int
878 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
880 for (
size_t __i = 0; __i < __n; ++__i)
881 if (lt(__s1[__i], __s2[__i]))
883 else if (lt(__s2[__i], __s1[__i]))
888 static _GLIBCXX17_CONSTEXPR
size_t
889 length(
const char_type* __s)
892 while (!eq(__s[__i], char_type()))
897 static _GLIBCXX17_CONSTEXPR
const char_type*
898 find(
const char_type* __s,
size_t __n,
const char_type& __a)
900 for (
size_t __i = 0; __i < __n; ++__i)
901 if (eq(__s[__i], __a))
906 static _GLIBCXX20_CONSTEXPR char_type*
907 move(char_type* __s1,
const char_type* __s2,
size_t __n)
911#ifdef __cpp_lib_is_constant_evaluated
912 if (std::is_constant_evaluated())
915 return (
static_cast<char_type*
>
916 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
919 static _GLIBCXX20_CONSTEXPR char_type*
920 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
924#ifdef __cpp_lib_is_constant_evaluated
925 if (std::is_constant_evaluated())
928 return (
static_cast<char_type*
>
929 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
932 static _GLIBCXX20_CONSTEXPR char_type*
933 assign(char_type* __s,
size_t __n, char_type __a)
935 for (
size_t __i = 0; __i < __n; ++__i)
936 assign(__s[__i], __a);
940 static constexpr char_type
941 to_char_type(
const int_type& __c)
noexcept
942 {
return char_type(__c); }
944 static constexpr int_type
945 to_int_type(
const char_type& __c)
noexcept
946 {
return int_type(__c); }
948 static constexpr bool
949 eq_int_type(
const int_type& __c1,
const int_type& __c2)
noexcept
950 {
return __c1 == __c2; }
952 static constexpr int_type
954 {
return static_cast<int_type
>(-1); }
956 static constexpr int_type
957 not_eof(
const int_type& __c)
noexcept
958 {
return eq_int_type(__c, eof()) ? 0 : __c; }
961#if __cpp_lib_three_way_comparison
964 template<
typename _ChTraits>
966 __char_traits_cmp_cat(
int __cmp)
noexcept
968 if constexpr (
requires {
typename _ChTraits::comparison_category; })
970 using _Cat =
typename _ChTraits::comparison_category;
971 static_assert( !is_void_v<common_comparison_category_t<_Cat>> );
972 return static_cast<_Cat
>(__cmp <=> 0);
975 return static_cast<weak_ordering
>(__cmp <=> 0);
980_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
fpos< mbstate_t > u32streampos
File position for char32_t streams.
constexpr bool __constant_char_array_p(const _CharT *__a, size_t __n)
Determine whether the characters of a character array are known at compile time.
long long streamoff
Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
fpos< mbstate_t > u16streampos
File position for char16_t streams.
constexpr bool __constant_string_p(const _CharT *__s)
Determine whether the characters of a NULL-terminated string are known at compile time.
GNU extensions for public use.
Mapping from character type to associated types.
Base class used to implement std::char_traits.
Basis for explicit traits specializations.
Class representing stream positions.