35#define _CHAR_TRAITS_H 1
37#pragma GCC system_header
41#if __cplusplus >= 201103L
44#if __cplusplus >= 202002L
49#ifndef _GLIBCXX_ALWAYS_INLINE
50# define _GLIBCXX_ALWAYS_INLINE inline __attribute__((__always_inline__))
53namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
55_GLIBCXX_BEGIN_NAMESPACE_VERSION
57#pragma GCC diagnostic push
58#pragma GCC diagnostic ignored "-Wstringop-overflow"
59#pragma GCC diagnostic ignored "-Wstringop-overread"
60#pragma GCC diagnostic ignored "-Warray-bounds"
72 template<
typename _CharT>
75 typedef unsigned long int_type;
78 typedef std::mbstate_t state_type;
97 template<
typename _CharT>
100 typedef _CharT char_type;
101 typedef typename _Char_types<_CharT>::int_type int_type;
104 typedef typename _Char_types<_CharT>::state_type state_type;
105#if __cpp_lib_three_way_comparison
106 using comparison_category = std::strong_ordering;
109 static _GLIBCXX14_CONSTEXPR
void
110 assign(char_type& __c1,
const char_type& __c2)
112#if __cpp_constexpr_dynamic_alloc
113 if (std::__is_constant_evaluated())
114 std::construct_at(__builtin_addressof(__c1), __c2);
120 static _GLIBCXX_CONSTEXPR
bool
121 eq(
const char_type& __c1,
const char_type& __c2)
122 {
return __c1 == __c2; }
124 static _GLIBCXX_CONSTEXPR
bool
125 lt(
const char_type& __c1,
const char_type& __c2)
126 {
return __c1 < __c2; }
128 static _GLIBCXX14_CONSTEXPR
int
129 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n);
131 static _GLIBCXX14_CONSTEXPR std::size_t
132 length(
const char_type* __s);
134 static _GLIBCXX14_CONSTEXPR
const char_type*
135 find(
const char_type* __s, std::size_t __n,
const char_type& __a);
137 static _GLIBCXX20_CONSTEXPR char_type*
138 move(char_type* __s1,
const char_type* __s2, std::size_t __n);
140 static _GLIBCXX20_CONSTEXPR char_type*
141 copy(char_type* __s1,
const char_type* __s2, std::size_t __n);
143 static _GLIBCXX20_CONSTEXPR char_type*
144 assign(char_type* __s, std::size_t __n, char_type __a);
146 static _GLIBCXX_CONSTEXPR char_type
147 to_char_type(
const int_type& __c)
148 {
return static_cast<char_type
>(__c); }
150 static _GLIBCXX_CONSTEXPR int_type
151 to_int_type(
const char_type& __c)
152 {
return static_cast<int_type
>(__c); }
154 static _GLIBCXX_CONSTEXPR
bool
155 eq_int_type(
const int_type& __c1,
const int_type& __c2)
156 {
return __c1 == __c2; }
158 static _GLIBCXX_CONSTEXPR int_type
160 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
162 static _GLIBCXX_CONSTEXPR int_type
163 not_eof(
const int_type& __c)
164 {
return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
167 template<
typename _CharT>
168 _GLIBCXX14_CONSTEXPR
int
170 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n)
172 for (std::size_t __i = 0; __i < __n; ++__i)
173 if (lt(__s1[__i], __s2[__i]))
175 else if (lt(__s2[__i], __s1[__i]))
180 template<
typename _CharT>
181 _GLIBCXX14_CONSTEXPR std::size_t
182 char_traits<_CharT>::
183 length(
const char_type* __p)
186 while (!eq(__p[__i], char_type()))
191 template<
typename _CharT>
192 _GLIBCXX14_CONSTEXPR
const typename char_traits<_CharT>::char_type*
193 char_traits<_CharT>::
194 find(
const char_type* __s, std::size_t __n,
const char_type& __a)
196 for (std::size_t __i = 0; __i < __n; ++__i)
197 if (eq(__s[__i], __a))
202 template<
typename _CharT>
204 typename char_traits<_CharT>::char_type*
205 char_traits<_CharT>::
206 move(char_type* __s1,
const char_type* __s2, std::size_t __n)
210#if __cplusplus >= 202002L
211 if (std::__is_constant_evaluated())
213#if __cpp_constexpr_dynamic_alloc
216 char_type* __tmp =
new char_type[__n];
217 copy(__tmp, __s2, __n);
218 copy(__s1, __tmp, __n);
222 if (__builtin_constant_p(__s2 < __s1)
223 && __s1 > __s2 && __s1 < (__s2 + __n))
228 assign(__s1[__n], __s2[__n]);
233 copy(__s1, __s2, __n);
238 __builtin_memmove(__s1, __s2, __n *
sizeof(char_type));
242 template<
typename _CharT>
244 typename char_traits<_CharT>::char_type*
245 char_traits<_CharT>::
246 copy(char_type* __s1,
const char_type* __s2, std::size_t __n)
250#if __cplusplus >= 202002L
251 if (std::__is_constant_evaluated())
253 for (std::size_t __i = 0; __i < __n; ++__i)
254 std::construct_at(__s1 + __i, __s2[__i]);
258 __builtin_memcpy(__s1, __s2, __n *
sizeof(char_type));
262 template<
typename _CharT>
264 typename char_traits<_CharT>::char_type*
265 char_traits<_CharT>::
266 assign(char_type* __s, std::size_t __n, char_type __a)
268#if __cplusplus >= 202002L
269 if (std::__is_constant_evaluated())
271 for (std::size_t __i = 0; __i < __n; ++__i)
272 std::construct_at(__s + __i, __a);
277 if _GLIBCXX17_CONSTEXPR (
sizeof(_CharT) == 1 && __is_trivial(_CharT))
282 __builtin_memcpy(&__c, __builtin_addressof(__a), 1);
283 __builtin_memset(__s, __c, __n);
288 for (std::size_t __i = 0; __i < __n; ++__i)
294_GLIBCXX_END_NAMESPACE_VERSION
297namespace std _GLIBCXX_VISIBILITY(default)
299_GLIBCXX_BEGIN_NAMESPACE_VERSION
301#ifdef __cpp_lib_is_constant_evaluated
303# define __cpp_lib_constexpr_char_traits 201811L
304#elif __cplusplus >= 201703L && _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED
306# define __cpp_lib_constexpr_char_traits 201611L
322 template<
typename _CharT>
331 typedef char char_type;
332 typedef int int_type;
335 typedef mbstate_t state_type;
336#if __cpp_lib_three_way_comparison
343#if __cpp_constexpr_dynamic_alloc
344 if (std::__is_constant_evaluated())
353 {
return __c1 == __c2; }
359 return (
static_cast<unsigned char>(
__c1)
360 <
static_cast<unsigned char>(__c2));
364 compare(
const char_type*
__s1,
const char_type*
__s2,
size_t __n)
368#if __cplusplus >= 201703L
369 if (std::__is_constant_evaluated())
371 for (
size_t __i = 0; __i < __n; ++__i)
383 length(
const char_type*
__s)
385#if __cplusplus >= 201703L
386 if (std::__is_constant_evaluated())
393 find(
const char_type*
__s,
size_t __n,
const char_type& __a)
397#if __cplusplus >= 201703L
398 if (std::__is_constant_evaluated())
405 move(char_type*
__s1,
const char_type*
__s2,
size_t __n)
409#if __cplusplus >= 202002L
410 if (std::__is_constant_evaluated())
417 copy(char_type*
__s1,
const char_type*
__s2,
size_t __n)
421#if __cplusplus >= 202002L
422 if (std::__is_constant_evaluated())
429 assign(char_type*
__s,
size_t __n, char_type __a)
433#if __cplusplus >= 202002L
434 if (std::__is_constant_evaluated())
442 {
return static_cast<char_type
>(__c); }
448 {
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
452 {
return __c1 == __c2; }
456 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
460 {
return (__c == eof()) ? 0 : __c; }
464#ifdef _GLIBCXX_USE_WCHAR_T
469 typedef wchar_t char_type;
470 typedef wint_t int_type;
473 typedef mbstate_t state_type;
474#if __cpp_lib_three_way_comparison
481#if __cpp_constexpr_dynamic_alloc
482 if (std::__is_constant_evaluated())
491 {
return __c1 == __c2; }
495 {
return __c1 < __c2; }
498 compare(
const char_type*
__s1,
const char_type*
__s2,
size_t __n)
502#if __cplusplus >= 201703L
503 if (std::__is_constant_evaluated())
510 length(
const char_type*
__s)
512#if __cplusplus >= 201703L
513 if (std::__is_constant_evaluated())
520 find(
const char_type*
__s,
size_t __n,
const char_type& __a)
524#if __cplusplus >= 201703L
525 if (std::__is_constant_evaluated())
528 return wmemchr(
__s, __a, __n);
532 move(char_type*
__s1,
const char_type*
__s2,
size_t __n)
536#if __cplusplus >= 202002L
537 if (std::__is_constant_evaluated())
544 copy(char_type*
__s1,
const char_type*
__s2,
size_t __n)
548#if __cplusplus >= 202002L
549 if (std::__is_constant_evaluated())
556 assign(char_type*
__s,
size_t __n, char_type __a)
560#if __cplusplus >= 202002L
561 if (std::__is_constant_evaluated())
569 {
return char_type(__c); }
573 {
return int_type(__c); }
577 {
return __c1 == __c2; }
581 {
return static_cast<int_type
>(
WEOF); }
585 {
return eq_int_type(__c, eof()) ? 0 : __c; }
593#ifdef _GLIBCXX_USE_CHAR8_T
595 struct char_traits<char8_t>
597 typedef char8_t char_type;
598 typedef unsigned int int_type;
599 typedef u8streampos pos_type;
601 typedef mbstate_t state_type;
602#if __cpp_lib_three_way_comparison
603 using comparison_category = strong_ordering;
606 static _GLIBCXX17_CONSTEXPR
void
607 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
609#if __cpp_constexpr_dynamic_alloc
610 if (std::__is_constant_evaluated())
611 std::construct_at(__builtin_addressof(__c1), __c2);
617 static _GLIBCXX_CONSTEXPR
bool
618 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
619 {
return __c1 == __c2; }
621 static _GLIBCXX_CONSTEXPR
bool
622 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
623 {
return __c1 < __c2; }
625 static _GLIBCXX17_CONSTEXPR
int
626 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
630#if __cplusplus >= 201703L
631 if (std::__is_constant_evaluated())
634 return __builtin_memcmp(__s1, __s2, __n);
637 static _GLIBCXX17_CONSTEXPR
size_t
638 length(
const char_type* __s)
640#if __cplusplus >= 201703L
641 if (std::__is_constant_evaluated())
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 >= 201703L
656 if (std::__is_constant_evaluated())
659 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
662 static _GLIBCXX20_CONSTEXPR char_type*
663 move(char_type* __s1,
const char_type* __s2,
size_t __n)
667#if __cplusplus >= 202002L
668 if (std::__is_constant_evaluated())
671 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
674 static _GLIBCXX20_CONSTEXPR char_type*
675 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
679#if __cplusplus >= 202002L
680 if (std::__is_constant_evaluated())
683 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
686 static _GLIBCXX20_CONSTEXPR char_type*
687 assign(char_type* __s,
size_t __n, char_type __a)
691#if __cplusplus >= 202002L
692 if (std::__is_constant_evaluated())
695 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
698 static _GLIBCXX_CONSTEXPR char_type
699 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
700 {
return char_type(__c); }
702 static _GLIBCXX_CONSTEXPR int_type
703 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
704 {
return int_type(__c); }
706 static _GLIBCXX_CONSTEXPR
bool
707 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
708 {
return __c1 == __c2; }
710 static _GLIBCXX_CONSTEXPR int_type
711 eof() _GLIBCXX_NOEXCEPT
712 {
return static_cast<int_type
>(-1); }
714 static _GLIBCXX_CONSTEXPR int_type
715 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
716 {
return eq_int_type(__c, eof()) ? 0 : __c; }
720_GLIBCXX_END_NAMESPACE_VERSION
723#if __cplusplus >= 201103L
727namespace std _GLIBCXX_VISIBILITY(default)
729_GLIBCXX_BEGIN_NAMESPACE_VERSION
732 struct char_traits<char16_t>
734 typedef char16_t char_type;
735#ifdef _GLIBCXX_USE_C99_STDINT_TR1
736 typedef uint_least16_t int_type;
737#elif defined __UINT_LEAST16_TYPE__
738 typedef __UINT_LEAST16_TYPE__ int_type;
740 typedef make_unsigned<char16_t>::type int_type;
744 typedef mbstate_t state_type;
745#if __cpp_lib_three_way_comparison
746 using comparison_category = strong_ordering;
749 static _GLIBCXX17_CONSTEXPR
void
750 assign(char_type& __c1,
const char_type& __c2)
noexcept
752#if __cpp_constexpr_dynamic_alloc
753 if (std::__is_constant_evaluated())
754 std::construct_at(__builtin_addressof(__c1), __c2);
760 static constexpr bool
761 eq(
const char_type& __c1,
const char_type& __c2)
noexcept
762 {
return __c1 == __c2; }
764 static constexpr bool
765 lt(
const char_type& __c1,
const char_type& __c2)
noexcept
766 {
return __c1 < __c2; }
768 static _GLIBCXX17_CONSTEXPR
int
769 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
771 for (
size_t __i = 0; __i < __n; ++__i)
772 if (lt(__s1[__i], __s2[__i]))
774 else if (lt(__s2[__i], __s1[__i]))
779 static _GLIBCXX17_CONSTEXPR
size_t
780 length(
const char_type* __s)
783 while (!eq(__s[__i], char_type()))
788 static _GLIBCXX17_CONSTEXPR
const char_type*
789 find(
const char_type* __s,
size_t __n,
const char_type& __a)
791 for (
size_t __i = 0; __i < __n; ++__i)
792 if (eq(__s[__i], __a))
797 static _GLIBCXX20_CONSTEXPR char_type*
798 move(char_type* __s1,
const char_type* __s2,
size_t __n)
802#if __cplusplus >= 202002L
803 if (std::__is_constant_evaluated())
806 return (
static_cast<char_type*
>
807 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
810 static _GLIBCXX20_CONSTEXPR char_type*
811 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
815#if __cplusplus >= 202002L
816 if (std::__is_constant_evaluated())
819 return (
static_cast<char_type*
>
820 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
823 static _GLIBCXX20_CONSTEXPR char_type*
824 assign(char_type* __s,
size_t __n, char_type __a)
826 for (
size_t __i = 0; __i < __n; ++__i)
827 assign(__s[__i], __a);
831 static constexpr char_type
832 to_char_type(
const int_type& __c)
noexcept
833 {
return char_type(__c); }
835 static constexpr int_type
836 to_int_type(
const char_type& __c)
noexcept
837 {
return __c == eof() ? int_type(0xfffd) : int_type(__c); }
839 static constexpr bool
840 eq_int_type(
const int_type& __c1,
const int_type& __c2)
noexcept
841 {
return __c1 == __c2; }
843 static constexpr int_type
845 {
return static_cast<int_type
>(-1); }
847 static constexpr int_type
848 not_eof(
const int_type& __c)
noexcept
849 {
return eq_int_type(__c, eof()) ? 0 : __c; }
853 struct char_traits<char32_t>
855 typedef char32_t char_type;
856#ifdef _GLIBCXX_USE_C99_STDINT_TR1
857 typedef uint_least32_t int_type;
858#elif defined __UINT_LEAST32_TYPE__
859 typedef __UINT_LEAST32_TYPE__ int_type;
861 typedef make_unsigned<char32_t>::type int_type;
865 typedef mbstate_t state_type;
866#if __cpp_lib_three_way_comparison
867 using comparison_category = strong_ordering;
870 static _GLIBCXX17_CONSTEXPR
void
871 assign(char_type& __c1,
const char_type& __c2)
noexcept
873#if __cpp_constexpr_dynamic_alloc
874 if (std::__is_constant_evaluated())
875 std::construct_at(__builtin_addressof(__c1), __c2);
881 static constexpr bool
882 eq(
const char_type& __c1,
const char_type& __c2)
noexcept
883 {
return __c1 == __c2; }
885 static constexpr bool
886 lt(
const char_type& __c1,
const char_type& __c2)
noexcept
887 {
return __c1 < __c2; }
889 static _GLIBCXX17_CONSTEXPR
int
890 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
892 for (
size_t __i = 0; __i < __n; ++__i)
893 if (lt(__s1[__i], __s2[__i]))
895 else if (lt(__s2[__i], __s1[__i]))
900 static _GLIBCXX17_CONSTEXPR
size_t
901 length(
const char_type* __s)
904 while (!eq(__s[__i], char_type()))
909 static _GLIBCXX17_CONSTEXPR
const char_type*
910 find(
const char_type* __s,
size_t __n,
const char_type& __a)
912 for (
size_t __i = 0; __i < __n; ++__i)
913 if (eq(__s[__i], __a))
918 static _GLIBCXX20_CONSTEXPR char_type*
919 move(char_type* __s1,
const char_type* __s2,
size_t __n)
923#if __cplusplus >= 202002L
924 if (std::__is_constant_evaluated())
927 return (
static_cast<char_type*
>
928 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
931 static _GLIBCXX20_CONSTEXPR char_type*
932 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
936#if __cplusplus >= 202002L
937 if (std::__is_constant_evaluated())
940 return (
static_cast<char_type*
>
941 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
944 static _GLIBCXX20_CONSTEXPR char_type*
945 assign(char_type* __s,
size_t __n, char_type __a)
947 for (
size_t __i = 0; __i < __n; ++__i)
948 assign(__s[__i], __a);
952 static constexpr char_type
953 to_char_type(
const int_type& __c)
noexcept
954 {
return char_type(__c); }
956 static constexpr int_type
957 to_int_type(
const char_type& __c)
noexcept
958 {
return int_type(__c); }
960 static constexpr bool
961 eq_int_type(
const int_type& __c1,
const int_type& __c2)
noexcept
962 {
return __c1 == __c2; }
964 static constexpr int_type
966 {
return static_cast<int_type
>(-1); }
968 static constexpr int_type
969 not_eof(
const int_type& __c)
noexcept
970 {
return eq_int_type(__c, eof()) ? 0 : __c; }
973#if __cpp_lib_three_way_comparison
976 template<
typename _ChTraits>
978 __char_traits_cmp_cat(
int __cmp)
noexcept
980 if constexpr (
requires {
typename _ChTraits::comparison_category; })
982 using _Cat =
typename _ChTraits::comparison_category;
983 static_assert( !is_void_v<common_comparison_category_t<_Cat>> );
984 return static_cast<_Cat
>(__cmp <=> 0);
987 return static_cast<weak_ordering
>(__cmp <=> 0);
992#pragma GCC diagnostic pop
994_GLIBCXX_END_NAMESPACE_VERSION
ISO C++ entities toplevel namespace is std.
fpos< mbstate_t > u32streampos
File position for char32_t streams.
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.
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.