35#define _CHAR_TRAITS_H 1
37#pragma GCC system_header
45#ifdef _GLIBCXX_USE_WCHAR_T
49#if __cplusplus >= 201103L
51#if !defined __UINT_LEAST16_TYPE__ || !defined __UINT_LEAST32_TYPE__
55#if __cplusplus >= 202002L
60#ifndef _GLIBCXX_ALWAYS_INLINE
61# define _GLIBCXX_ALWAYS_INLINE inline __attribute__((__always_inline__))
64namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
66_GLIBCXX_BEGIN_NAMESPACE_VERSION
68#pragma GCC diagnostic push
69#pragma GCC diagnostic ignored "-Wstringop-overflow"
70#pragma GCC diagnostic ignored "-Wstringop-overread"
71#pragma GCC diagnostic ignored "-Warray-bounds"
83 template<
typename _CharT>
86 typedef unsigned long int_type;
90 typedef std::mbstate_t state_type;
110 template<
typename _CharT>
113 typedef _CharT char_type;
114 typedef typename _Char_types<_CharT>::int_type int_type;
118 typedef typename _Char_types<_CharT>::state_type state_type;
120#if __cpp_lib_three_way_comparison
121 using comparison_category = std::strong_ordering;
124 static _GLIBCXX14_CONSTEXPR
void
125 assign(char_type& __c1,
const char_type& __c2)
127#if __cpp_constexpr_dynamic_alloc
128 if (std::__is_constant_evaluated())
129 std::construct_at(__builtin_addressof(__c1), __c2);
135 static _GLIBCXX_CONSTEXPR
bool
136 eq(
const char_type& __c1,
const char_type& __c2)
137 {
return __c1 == __c2; }
139 static _GLIBCXX_CONSTEXPR
bool
140 lt(
const char_type& __c1,
const char_type& __c2)
141 {
return __c1 < __c2; }
143 static _GLIBCXX14_CONSTEXPR
int
144 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n);
146 static _GLIBCXX14_CONSTEXPR std::size_t
147 length(
const char_type* __s);
149 static _GLIBCXX14_CONSTEXPR
const char_type*
150 find(
const char_type* __s, std::size_t __n,
const char_type& __a);
152 static _GLIBCXX20_CONSTEXPR char_type*
153 move(char_type* __s1,
const char_type* __s2, std::size_t __n);
155 static _GLIBCXX20_CONSTEXPR char_type*
156 copy(char_type* __s1,
const char_type* __s2, std::size_t __n);
158 static _GLIBCXX20_CONSTEXPR char_type*
159 assign(char_type* __s, std::size_t __n, char_type __a);
161 static _GLIBCXX_CONSTEXPR char_type
162 to_char_type(
const int_type& __c)
163 {
return static_cast<char_type
>(__c); }
165 static _GLIBCXX_CONSTEXPR int_type
166 to_int_type(
const char_type& __c)
167 {
return static_cast<int_type
>(__c); }
169 static _GLIBCXX_CONSTEXPR
bool
170 eq_int_type(
const int_type& __c1,
const int_type& __c2)
171 {
return __c1 == __c2; }
173#ifdef _GLIBCXX_STDIO_EOF
174 static _GLIBCXX_CONSTEXPR int_type
176 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
178 static _GLIBCXX_CONSTEXPR int_type
179 not_eof(
const int_type& __c)
180 {
return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
184 template<
typename _CharT>
185 _GLIBCXX14_CONSTEXPR
int
187 compare(
const char_type* __s1,
const char_type* __s2, std::size_t __n)
189 for (std::size_t __i = 0; __i < __n; ++__i)
190 if (lt(__s1[__i], __s2[__i]))
192 else if (lt(__s2[__i], __s1[__i]))
197 template<
typename _CharT>
198 _GLIBCXX14_CONSTEXPR std::size_t
199 char_traits<_CharT>::
200 length(
const char_type* __p)
203 while (!eq(__p[__i], char_type()))
208 template<
typename _CharT>
209 _GLIBCXX14_CONSTEXPR
const typename char_traits<_CharT>::char_type*
210 char_traits<_CharT>::
211 find(
const char_type* __s, std::size_t __n,
const char_type& __a)
213 for (std::size_t __i = 0; __i < __n; ++__i)
214 if (eq(__s[__i], __a))
219 template<
typename _CharT>
221 typename char_traits<_CharT>::char_type*
222 char_traits<_CharT>::
223 move(char_type* __s1,
const char_type* __s2, std::size_t __n)
227#if __cplusplus >= 202002L
228 if (std::__is_constant_evaluated())
231 if (__builtin_constant_p(__s2 < __s1)
232 && __s1 > __s2 && __s1 < (__s2 + __n))
237 assign(__s1[__n], __s2[__n]);
242 copy(__s1, __s2, __n);
246 __builtin_memmove(__s1, __s2, __n *
sizeof(char_type));
250 template<
typename _CharT>
252 typename char_traits<_CharT>::char_type*
253 char_traits<_CharT>::
254 copy(char_type* __s1,
const char_type* __s2, std::size_t __n)
258#if __cplusplus >= 202002L
259 if (std::__is_constant_evaluated())
261 for (std::size_t __i = 0; __i < __n; ++__i)
262 std::construct_at(__s1 + __i, __s2[__i]);
266 __builtin_memcpy(__s1, __s2, __n *
sizeof(char_type));
270 template<
typename _CharT>
272 typename char_traits<_CharT>::char_type*
273 char_traits<_CharT>::
274 assign(char_type* __s, std::size_t __n, char_type __a)
276#if __cplusplus >= 202002L
277 if (std::__is_constant_evaluated())
279 for (std::size_t __i = 0; __i < __n; ++__i)
280 std::construct_at(__s + __i, __a);
285 if _GLIBCXX17_CONSTEXPR (
sizeof(_CharT) == 1 && __is_trivial(_CharT))
290 __builtin_memcpy(&__c, __builtin_addressof(__a), 1);
291 __builtin_memset(__s, __c, __n);
296 for (std::size_t __i = 0; __i < __n; ++__i)
302_GLIBCXX_END_NAMESPACE_VERSION
305namespace std _GLIBCXX_VISIBILITY(default)
307_GLIBCXX_BEGIN_NAMESPACE_VERSION
322 template<
typename _CharT>
331 typedef char char_type;
332 typedef int int_type;
336 typedef mbstate_t state_type;
338#if __cpp_lib_three_way_comparison
339 using comparison_category = strong_ordering;
345#if __cpp_constexpr_dynamic_alloc
346 if (std::__is_constant_evaluated())
355 {
return __c1 == __c2; }
361 return (
static_cast<unsigned char>(
__c1)
362 <
static_cast<unsigned char>(__c2));
366 compare(
const char_type*
__s1,
const char_type*
__s2,
size_t __n)
370#if __cplusplus >= 201703L
371 if (std::__is_constant_evaluated())
373 for (
size_t __i = 0; __i < __n; ++__i)
385 length(
const char_type*
__s)
387#if __cplusplus >= 201703L
388 if (std::__is_constant_evaluated())
395 find(
const char_type*
__s,
size_t __n,
const char_type& __a)
399#if __cplusplus >= 201703L
400 if (std::__is_constant_evaluated())
407 move(char_type*
__s1,
const char_type*
__s2,
size_t __n)
411#if __cplusplus >= 202002L
412 if (std::__is_constant_evaluated())
419 copy(char_type*
__s1,
const char_type*
__s2,
size_t __n)
423#if __cplusplus >= 202002L
424 if (std::__is_constant_evaluated())
431 assign(char_type*
__s,
size_t __n, char_type __a)
435#if __cplusplus >= 202002L
436 if (std::__is_constant_evaluated())
444 {
return static_cast<char_type
>(__c); }
450 {
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
454 {
return __c1 == __c2; }
456#ifdef _GLIBCXX_STDIO_EOF
459 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
463 {
return (__c == eof()) ? 0 : __c; }
468#ifdef _GLIBCXX_USE_WCHAR_T
473 typedef wchar_t char_type;
474 typedef wint_t int_type;
478 typedef mbstate_t state_type;
480#if __cpp_lib_three_way_comparison
481 using comparison_category = strong_ordering;
487#if __cpp_constexpr_dynamic_alloc
488 if (std::__is_constant_evaluated())
497 {
return __c1 == __c2; }
501 {
return __c1 < __c2; }
504 compare(
const char_type*
__s1,
const char_type*
__s2,
size_t __n)
508#if __cplusplus >= 201703L
509 if (std::__is_constant_evaluated())
516 length(
const char_type*
__s)
518#if __cplusplus >= 201703L
519 if (std::__is_constant_evaluated())
526 find(
const char_type*
__s,
size_t __n,
const char_type& __a)
530#if __cplusplus >= 201703L
531 if (std::__is_constant_evaluated())
534 return wmemchr(
__s, __a, __n);
538 move(char_type*
__s1,
const char_type*
__s2,
size_t __n)
542#if __cplusplus >= 202002L
543 if (std::__is_constant_evaluated())
550 copy(char_type*
__s1,
const char_type*
__s2,
size_t __n)
554#if __cplusplus >= 202002L
555 if (std::__is_constant_evaluated())
562 assign(char_type*
__s,
size_t __n, char_type __a)
566#if __cplusplus >= 202002L
567 if (std::__is_constant_evaluated())
575 {
return char_type(__c); }
579 {
return int_type(__c); }
583 {
return __c1 == __c2; }
588 {
return static_cast<int_type
>(
WEOF); }
592 {
return eq_int_type(__c, eof()) ? 0 : __c; }
601#ifdef _GLIBCXX_USE_CHAR8_T
603 struct char_traits<char8_t>
605 typedef char8_t char_type;
606 typedef unsigned int int_type;
608 typedef u8streampos pos_type;
610 typedef mbstate_t state_type;
612#if __cpp_lib_three_way_comparison
613 using comparison_category = strong_ordering;
616 static _GLIBCXX17_CONSTEXPR
void
617 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
619#if __cpp_constexpr_dynamic_alloc
620 if (std::__is_constant_evaluated())
621 std::construct_at(__builtin_addressof(__c1), __c2);
627 static _GLIBCXX_CONSTEXPR
bool
628 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
629 {
return __c1 == __c2; }
631 static _GLIBCXX_CONSTEXPR
bool
632 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
633 {
return __c1 < __c2; }
635 static _GLIBCXX17_CONSTEXPR
int
636 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
640#if __cplusplus >= 201703L
641 if (std::__is_constant_evaluated())
644 return __builtin_memcmp(__s1, __s2, __n);
647 static _GLIBCXX17_CONSTEXPR
size_t
648 length(
const char_type* __s)
650#if __cplusplus >= 201703L
651 if (std::__is_constant_evaluated())
655 while (!eq(__s[__i], char_type()))
660 static _GLIBCXX17_CONSTEXPR
const char_type*
661 find(
const char_type* __s,
size_t __n,
const char_type& __a)
665#if __cplusplus >= 201703L
666 if (std::__is_constant_evaluated())
669 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
672 static _GLIBCXX20_CONSTEXPR char_type*
673 move(char_type* __s1,
const char_type* __s2,
size_t __n)
677#if __cplusplus >= 202002L
678 if (std::__is_constant_evaluated())
681 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
684 static _GLIBCXX20_CONSTEXPR char_type*
685 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
689#if __cplusplus >= 202002L
690 if (std::__is_constant_evaluated())
693 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
696 static _GLIBCXX20_CONSTEXPR char_type*
697 assign(char_type* __s,
size_t __n, char_type __a)
701#if __cplusplus >= 202002L
702 if (std::__is_constant_evaluated())
705 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
708 static _GLIBCXX_CONSTEXPR char_type
709 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
710 {
return char_type(__c); }
712 static _GLIBCXX_CONSTEXPR int_type
713 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
714 {
return int_type(__c); }
716 static _GLIBCXX_CONSTEXPR
bool
717 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
718 {
return __c1 == __c2; }
721 static _GLIBCXX_CONSTEXPR int_type
722 eof() _GLIBCXX_NOEXCEPT
723 {
return static_cast<int_type
>(-1); }
725 static _GLIBCXX_CONSTEXPR int_type
726 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
727 {
return eq_int_type(__c, eof()) ? 0 : __c; }
732_GLIBCXX_END_NAMESPACE_VERSION
735#if __cplusplus >= 201103L
737namespace std _GLIBCXX_VISIBILITY(default)
739_GLIBCXX_BEGIN_NAMESPACE_VERSION
742 struct char_traits<char16_t>
744 typedef char16_t char_type;
745#ifdef __UINT_LEAST16_TYPE__
746 typedef __UINT_LEAST16_TYPE__ int_type;
748 typedef uint_least16_t int_type;
753 typedef mbstate_t state_type;
755#if __cpp_lib_three_way_comparison
756 using comparison_category = strong_ordering;
759 static _GLIBCXX17_CONSTEXPR
void
760 assign(char_type& __c1,
const char_type& __c2)
noexcept
762#if __cpp_constexpr_dynamic_alloc
763 if (std::__is_constant_evaluated())
764 std::construct_at(__builtin_addressof(__c1), __c2);
770 static constexpr bool
771 eq(
const char_type& __c1,
const char_type& __c2)
noexcept
772 {
return __c1 == __c2; }
774 static constexpr bool
775 lt(
const char_type& __c1,
const char_type& __c2)
noexcept
776 {
return __c1 < __c2; }
778 static _GLIBCXX17_CONSTEXPR
int
779 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
781 for (
size_t __i = 0; __i < __n; ++__i)
782 if (lt(__s1[__i], __s2[__i]))
784 else if (lt(__s2[__i], __s1[__i]))
789 static _GLIBCXX17_CONSTEXPR
size_t
790 length(
const char_type* __s)
793 while (!eq(__s[__i], char_type()))
798 static _GLIBCXX17_CONSTEXPR
const char_type*
799 find(
const char_type* __s,
size_t __n,
const char_type& __a)
801 for (
size_t __i = 0; __i < __n; ++__i)
802 if (eq(__s[__i], __a))
807 static _GLIBCXX20_CONSTEXPR char_type*
808 move(char_type* __s1,
const char_type* __s2,
size_t __n)
812#if __cplusplus >= 202002L
813 if (std::__is_constant_evaluated())
816 return (
static_cast<char_type*
>
817 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
820 static _GLIBCXX20_CONSTEXPR char_type*
821 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
825#if __cplusplus >= 202002L
826 if (std::__is_constant_evaluated())
829 return (
static_cast<char_type*
>
830 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
833 static _GLIBCXX20_CONSTEXPR char_type*
834 assign(char_type* __s,
size_t __n, char_type __a)
836 for (
size_t __i = 0; __i < __n; ++__i)
837 assign(__s[__i], __a);
841 static constexpr char_type
842 to_char_type(
const int_type& __c)
noexcept
843 {
return char_type(__c); }
845 static constexpr bool
846 eq_int_type(
const int_type& __c1,
const int_type& __c2)
noexcept
847 {
return __c1 == __c2; }
850 static constexpr int_type
851 to_int_type(
const char_type& __c)
noexcept
852 {
return __c == eof() ? int_type(0xfffd) : int_type(__c); }
854 static constexpr int_type
856 {
return static_cast<int_type
>(-1); }
858 static constexpr int_type
859 not_eof(
const int_type& __c)
noexcept
860 {
return eq_int_type(__c, eof()) ? 0 : __c; }
862 static constexpr int_type
863 to_int_type(
const char_type& __c)
noexcept
864 {
return int_type(__c); }
869 struct char_traits<char32_t>
871 typedef char32_t char_type;
872#ifdef __UINT_LEAST32_TYPE__
873 typedef __UINT_LEAST32_TYPE__ int_type;
875 typedef uint_least32_t int_type;
880 typedef mbstate_t state_type;
882#if __cpp_lib_three_way_comparison
883 using comparison_category = strong_ordering;
886 static _GLIBCXX17_CONSTEXPR
void
887 assign(char_type& __c1,
const char_type& __c2)
noexcept
889#if __cpp_constexpr_dynamic_alloc
890 if (std::__is_constant_evaluated())
891 std::construct_at(__builtin_addressof(__c1), __c2);
897 static constexpr bool
898 eq(
const char_type& __c1,
const char_type& __c2)
noexcept
899 {
return __c1 == __c2; }
901 static constexpr bool
902 lt(
const char_type& __c1,
const char_type& __c2)
noexcept
903 {
return __c1 < __c2; }
905 static _GLIBCXX17_CONSTEXPR
int
906 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
908 for (
size_t __i = 0; __i < __n; ++__i)
909 if (lt(__s1[__i], __s2[__i]))
911 else if (lt(__s2[__i], __s1[__i]))
916 static _GLIBCXX17_CONSTEXPR
size_t
917 length(
const char_type* __s)
920 while (!eq(__s[__i], char_type()))
925 static _GLIBCXX17_CONSTEXPR
const char_type*
926 find(
const char_type* __s,
size_t __n,
const char_type& __a)
928 for (
size_t __i = 0; __i < __n; ++__i)
929 if (eq(__s[__i], __a))
934 static _GLIBCXX20_CONSTEXPR char_type*
935 move(char_type* __s1,
const char_type* __s2,
size_t __n)
939#if __cplusplus >= 202002L
940 if (std::__is_constant_evaluated())
943 return (
static_cast<char_type*
>
944 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
947 static _GLIBCXX20_CONSTEXPR char_type*
948 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
952#if __cplusplus >= 202002L
953 if (std::__is_constant_evaluated())
956 return (
static_cast<char_type*
>
957 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
960 static _GLIBCXX20_CONSTEXPR char_type*
961 assign(char_type* __s,
size_t __n, char_type __a)
963 for (
size_t __i = 0; __i < __n; ++__i)
964 assign(__s[__i], __a);
968 static constexpr char_type
969 to_char_type(
const int_type& __c)
noexcept
970 {
return char_type(__c); }
972 static constexpr int_type
973 to_int_type(
const char_type& __c)
noexcept
974 {
return int_type(__c); }
976 static constexpr bool
977 eq_int_type(
const int_type& __c1,
const int_type& __c2)
noexcept
978 {
return __c1 == __c2; }
981 static constexpr int_type
983 {
return static_cast<int_type
>(-1); }
985 static constexpr int_type
986 not_eof(
const int_type& __c)
noexcept
987 {
return eq_int_type(__c, eof()) ? 0 : __c; }
991#if __cpp_lib_three_way_comparison
994 template<
typename _ChTraits>
996 __char_traits_cmp_cat(
int __cmp)
noexcept
998 if constexpr (
requires {
typename _ChTraits::comparison_category; })
1000 using _Cat =
typename _ChTraits::comparison_category;
1001 static_assert( !is_void_v<common_comparison_category_t<_Cat>> );
1002 return static_cast<_Cat
>(__cmp <=> 0);
1005 return static_cast<weak_ordering
>(__cmp <=> 0);
1010#pragma GCC diagnostic pop
1012_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.