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__))
47namespace __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);
117 move(char_type* __s1,
const char_type* __s2, std::size_t __n);
120 copy(char_type* __s1,
const char_type* __s2, std::size_t __n);
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>
182 typename char_traits<_CharT>::char_type*
183 char_traits<_CharT>::
184 move(char_type* __s1,
const char_type* __s2, std::size_t __n)
188 return static_cast<_CharT*
>(__builtin_memmove(__s1, __s2,
189 __n *
sizeof(char_type)));
192 template<
typename _CharT>
193 typename char_traits<_CharT>::char_type*
194 char_traits<_CharT>::
195 copy(char_type* __s1,
const char_type* __s2, std::size_t __n)
198 std::copy(__s2, __s2 + __n, __s1);
202 template<
typename _CharT>
203 typename char_traits<_CharT>::char_type*
204 char_traits<_CharT>::
205 assign(char_type* __s, std::size_t __n, char_type __a)
208 std::fill_n(__s, __n, __a);
212_GLIBCXX_END_NAMESPACE_VERSION
215namespace std _GLIBCXX_VISIBILITY(default)
217_GLIBCXX_BEGIN_NAMESPACE_VERSION
219#if __cplusplus >= 201703L
220#define __cpp_lib_constexpr_char_traits 201611
229 template<
typename _CharT>
230 _GLIBCXX_ALWAYS_INLINE
constexpr bool
231 __constant_string_p(
const _CharT* __s)
233#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
236 return __builtin_is_constant_evaluated();
238 while (__builtin_constant_p(*__s) && *__s)
240 return __builtin_constant_p(*__s);
252 template<
typename _CharT>
253 _GLIBCXX_ALWAYS_INLINE
constexpr bool
254 __constant_char_array_p(
const _CharT* __a,
size_t __n)
256#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
260 return __builtin_is_constant_evaluated();
263 while (__i < __n && __builtin_constant_p(__a[__i]))
283 template<
class _CharT>
292 typedef char char_type;
293 typedef int int_type;
296 typedef mbstate_t state_type;
298 static _GLIBCXX17_CONSTEXPR
void
299 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
302 static _GLIBCXX_CONSTEXPR
bool
303 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
304 {
return __c1 == __c2; }
306 static _GLIBCXX_CONSTEXPR
bool
307 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
310 return (
static_cast<unsigned char>(__c1)
311 <
static_cast<unsigned char>(__c2));
314 static _GLIBCXX17_CONSTEXPR
int
315 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
319#if __cplusplus >= 201703L
320 if (__builtin_constant_p(__n)
321 && __constant_char_array_p(__s1, __n)
322 && __constant_char_array_p(__s2, __n))
324 for (
size_t __i = 0; __i < __n; ++__i)
325 if (lt(__s1[__i], __s2[__i]))
327 else if (lt(__s2[__i], __s1[__i]))
332 return __builtin_memcmp(__s1, __s2, __n);
335 static _GLIBCXX17_CONSTEXPR
size_t
336 length(
const char_type* __s)
338#if __cplusplus >= 201703L
339 if (__constant_string_p(__s))
342 return __builtin_strlen(__s);
345 static _GLIBCXX17_CONSTEXPR
const char_type*
346 find(
const char_type* __s,
size_t __n,
const char_type& __a)
350#if __cplusplus >= 201703L
351 if (__builtin_constant_p(__n)
352 && __builtin_constant_p(__a)
353 && __constant_char_array_p(__s, __n))
356 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
360 move(char_type* __s1,
const char_type* __s2,
size_t __n)
364 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
368 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
372 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
376 assign(char_type* __s,
size_t __n, char_type __a)
380 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
383 static _GLIBCXX_CONSTEXPR char_type
384 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
385 {
return static_cast<char_type
>(__c); }
389 static _GLIBCXX_CONSTEXPR int_type
390 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
391 {
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
393 static _GLIBCXX_CONSTEXPR
bool
394 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
395 {
return __c1 == __c2; }
397 static _GLIBCXX_CONSTEXPR int_type
398 eof() _GLIBCXX_NOEXCEPT
399 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
401 static _GLIBCXX_CONSTEXPR int_type
402 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
403 {
return (__c == eof()) ? 0 : __c; }
407#ifdef _GLIBCXX_USE_WCHAR_T
412 typedef wchar_t char_type;
413 typedef wint_t int_type;
416 typedef mbstate_t state_type;
418 static _GLIBCXX17_CONSTEXPR
void
419 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
422 static _GLIBCXX_CONSTEXPR
bool
423 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
424 {
return __c1 == __c2; }
426 static _GLIBCXX_CONSTEXPR
bool
427 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
428 {
return __c1 < __c2; }
430 static _GLIBCXX17_CONSTEXPR
int
431 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
435#if __cplusplus >= 201703L
436 if (__builtin_constant_p(__n)
437 && __constant_char_array_p(__s1, __n)
438 && __constant_char_array_p(__s2, __n))
441 return wmemcmp(__s1, __s2, __n);
444 static _GLIBCXX17_CONSTEXPR
size_t
445 length(
const char_type* __s)
447#if __cplusplus >= 201703L
448 if (__constant_string_p(__s))
454 static _GLIBCXX17_CONSTEXPR
const char_type*
455 find(
const char_type* __s,
size_t __n,
const char_type& __a)
459#if __cplusplus >= 201703L
460 if (__builtin_constant_p(__n)
461 && __builtin_constant_p(__a)
462 && __constant_char_array_p(__s, __n))
465 return wmemchr(__s, __a, __n);
469 move(char_type* __s1,
const char_type* __s2,
size_t __n)
473 return wmemmove(__s1, __s2, __n);
477 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
481 return wmemcpy(__s1, __s2, __n);
485 assign(char_type* __s,
size_t __n, char_type __a)
489 return wmemset(__s, __a, __n);
492 static _GLIBCXX_CONSTEXPR char_type
493 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
494 {
return char_type(__c); }
496 static _GLIBCXX_CONSTEXPR int_type
497 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
498 {
return int_type(__c); }
500 static _GLIBCXX_CONSTEXPR
bool
501 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
502 {
return __c1 == __c2; }
504 static _GLIBCXX_CONSTEXPR int_type
505 eof() _GLIBCXX_NOEXCEPT
506 {
return static_cast<int_type
>(WEOF); }
508 static _GLIBCXX_CONSTEXPR int_type
509 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
510 {
return eq_int_type(__c, eof()) ? 0 : __c; }
514#ifdef _GLIBCXX_USE_CHAR8_T
518 typedef char8_t char_type;
519 typedef unsigned int int_type;
520 typedef u8streampos pos_type;
522 typedef mbstate_t state_type;
524 static _GLIBCXX17_CONSTEXPR
void
525 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
528 static _GLIBCXX_CONSTEXPR
bool
529 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
530 {
return __c1 == __c2; }
532 static _GLIBCXX_CONSTEXPR
bool
533 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
534 {
return __c1 < __c2; }
536 static _GLIBCXX17_CONSTEXPR
int
537 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
541#if __cplusplus > 201402
542 if (__builtin_constant_p(__n)
543 && __constant_char_array_p(__s1, __n)
544 && __constant_char_array_p(__s2, __n))
547 return __builtin_memcmp(__s1, __s2, __n);
550 static _GLIBCXX17_CONSTEXPR
size_t
551 length(
const char_type* __s)
553#if __cplusplus > 201402
554 if (__constant_string_p(__s))
558 while (!eq(__s[__i], char_type()))
563 static _GLIBCXX17_CONSTEXPR
const char_type*
564 find(
const char_type* __s,
size_t __n,
const char_type& __a)
568#if __cplusplus > 201402
569 if (__builtin_constant_p(__n)
570 && __builtin_constant_p(__a)
571 && __constant_char_array_p(__s, __n))
574 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
578 move(char_type* __s1,
const char_type* __s2,
size_t __n)
582 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
586 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
590 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
594 assign(char_type* __s,
size_t __n, char_type __a)
598 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
601 static _GLIBCXX_CONSTEXPR char_type
602 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
603 {
return char_type(__c); }
605 static _GLIBCXX_CONSTEXPR int_type
606 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
607 {
return int_type(__c); }
609 static _GLIBCXX_CONSTEXPR
bool
610 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
611 {
return __c1 == __c2; }
613 static _GLIBCXX_CONSTEXPR int_type
614 eof() _GLIBCXX_NOEXCEPT
615 {
return static_cast<int_type
>(-1); }
617 static _GLIBCXX_CONSTEXPR int_type
618 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
619 {
return eq_int_type(__c, eof()) ? 0 : __c; }
623_GLIBCXX_END_NAMESPACE_VERSION
626#if __cplusplus >= 201103L
630namespace std _GLIBCXX_VISIBILITY(default)
632_GLIBCXX_BEGIN_NAMESPACE_VERSION
635 struct char_traits<char16_t>
637 typedef char16_t char_type;
638#ifdef _GLIBCXX_USE_C99_STDINT_TR1
639 typedef uint_least16_t int_type;
640#elif defined __UINT_LEAST16_TYPE__
641 typedef __UINT_LEAST16_TYPE__ int_type;
643 typedef make_unsigned<char16_t>::type int_type;
647 typedef mbstate_t state_type;
649 static _GLIBCXX17_CONSTEXPR
void
650 assign(char_type& __c1,
const char_type& __c2)
noexcept
653 static constexpr bool
654 eq(
const char_type& __c1,
const char_type& __c2)
noexcept
655 {
return __c1 == __c2; }
657 static constexpr bool
658 lt(
const char_type& __c1,
const char_type& __c2)
noexcept
659 {
return __c1 < __c2; }
661 static _GLIBCXX17_CONSTEXPR
int
662 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
664 for (
size_t __i = 0; __i < __n; ++__i)
665 if (lt(__s1[__i], __s2[__i]))
667 else if (lt(__s2[__i], __s1[__i]))
672 static _GLIBCXX17_CONSTEXPR
size_t
673 length(
const char_type* __s)
676 while (!eq(__s[__i], char_type()))
681 static _GLIBCXX17_CONSTEXPR
const char_type*
682 find(
const char_type* __s,
size_t __n,
const char_type& __a)
684 for (
size_t __i = 0; __i < __n; ++__i)
685 if (eq(__s[__i], __a))
691 move(char_type* __s1,
const char_type* __s2,
size_t __n)
695 return (
static_cast<char_type*
>
696 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
700 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
704 return (
static_cast<char_type*
>
705 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
709 assign(char_type* __s,
size_t __n, char_type __a)
711 for (
size_t __i = 0; __i < __n; ++__i)
712 assign(__s[__i], __a);
716 static constexpr char_type
717 to_char_type(
const int_type& __c)
noexcept
718 {
return char_type(__c); }
720 static constexpr int_type
721 to_int_type(
const char_type& __c)
noexcept
722 {
return __c == eof() ? int_type(0xfffd) : int_type(__c); }
724 static constexpr bool
725 eq_int_type(
const int_type& __c1,
const int_type& __c2)
noexcept
726 {
return __c1 == __c2; }
728 static constexpr int_type
730 {
return static_cast<int_type
>(-1); }
732 static constexpr int_type
733 not_eof(
const int_type& __c)
noexcept
734 {
return eq_int_type(__c, eof()) ? 0 : __c; }
738 struct char_traits<char32_t>
740 typedef char32_t char_type;
741#ifdef _GLIBCXX_USE_C99_STDINT_TR1
742 typedef uint_least32_t int_type;
743#elif defined __UINT_LEAST32_TYPE__
744 typedef __UINT_LEAST32_TYPE__ int_type;
746 typedef make_unsigned<char32_t>::type int_type;
750 typedef mbstate_t state_type;
752 static _GLIBCXX17_CONSTEXPR
void
753 assign(char_type& __c1,
const char_type& __c2)
noexcept
756 static constexpr bool
757 eq(
const char_type& __c1,
const char_type& __c2)
noexcept
758 {
return __c1 == __c2; }
760 static constexpr bool
761 lt(
const char_type& __c1,
const char_type& __c2)
noexcept
762 {
return __c1 < __c2; }
764 static _GLIBCXX17_CONSTEXPR
int
765 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
767 for (
size_t __i = 0; __i < __n; ++__i)
768 if (lt(__s1[__i], __s2[__i]))
770 else if (lt(__s2[__i], __s1[__i]))
775 static _GLIBCXX17_CONSTEXPR
size_t
776 length(
const char_type* __s)
779 while (!eq(__s[__i], char_type()))
784 static _GLIBCXX17_CONSTEXPR
const char_type*
785 find(
const char_type* __s,
size_t __n,
const char_type& __a)
787 for (
size_t __i = 0; __i < __n; ++__i)
788 if (eq(__s[__i], __a))
794 move(char_type* __s1,
const char_type* __s2,
size_t __n)
798 return (
static_cast<char_type*
>
799 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
803 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
807 return (
static_cast<char_type*
>
808 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
812 assign(char_type* __s,
size_t __n, char_type __a)
814 for (
size_t __i = 0; __i < __n; ++__i)
815 assign(__s[__i], __a);
819 static constexpr char_type
820 to_char_type(
const int_type& __c)
noexcept
821 {
return char_type(__c); }
823 static constexpr int_type
824 to_int_type(
const char_type& __c)
noexcept
825 {
return int_type(__c); }
827 static constexpr bool
828 eq_int_type(
const int_type& __c1,
const int_type& __c2)
noexcept
829 {
return __c1 == __c2; }
831 static constexpr int_type
833 {
return static_cast<int_type
>(-1); }
835 static constexpr int_type
836 not_eof(
const int_type& __c)
noexcept
837 {
return eq_int_type(__c, eof()) ? 0 : __c; }
840_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.