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);
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)
212 _GLIBCXX_END_NAMESPACE_VERSION
215 namespace 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 static _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 static _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 (__builtin_constant_p(__a[__i]) && __i < __n)
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)
317 #if __cplusplus >= 201703L 318 if (__builtin_constant_p(__n)
319 && __constant_char_array_p(__s1, __n)
320 && __constant_char_array_p(__s2, __n))
325 return __builtin_memcmp(__s1, __s2, __n);
328 static _GLIBCXX17_CONSTEXPR
size_t 329 length(
const char_type* __s)
331 #if __cplusplus >= 201703L 332 if (__constant_string_p(__s))
335 return __builtin_strlen(__s);
338 static _GLIBCXX17_CONSTEXPR
const char_type*
339 find(
const char_type* __s,
size_t __n,
const char_type& __a)
341 #if __cplusplus >= 201703L 342 if (__builtin_constant_p(__n)
343 && __builtin_constant_p(__a)
344 && __constant_char_array_p(__s, __n))
349 return static_cast<const char_type*>(__builtin_memchr(__s, __a, __n));
353 move(char_type* __s1,
const char_type* __s2,
size_t __n)
357 return static_cast<char_type*>(__builtin_memmove(__s1, __s2, __n));
361 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
365 return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
369 assign(char_type* __s,
size_t __n, char_type __a)
373 return static_cast<char_type*>(__builtin_memset(__s, __a, __n));
376 static _GLIBCXX_CONSTEXPR char_type
377 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
378 {
return static_cast<char_type>(__c); }
382 static _GLIBCXX_CONSTEXPR int_type
383 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
384 {
return static_cast<int_type>(static_cast<unsigned char>(__c)); }
386 static _GLIBCXX_CONSTEXPR
bool 387 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
388 {
return __c1 == __c2; }
390 static _GLIBCXX_CONSTEXPR int_type
391 eof() _GLIBCXX_NOEXCEPT
392 {
return static_cast<int_type>(_GLIBCXX_STDIO_EOF); }
394 static _GLIBCXX_CONSTEXPR int_type
395 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
396 {
return (__c == eof()) ? 0 : __c; }
400 #ifdef _GLIBCXX_USE_WCHAR_T 405 typedef wchar_t char_type;
406 typedef wint_t int_type;
409 typedef mbstate_t state_type;
411 static _GLIBCXX17_CONSTEXPR
void 412 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
415 static _GLIBCXX_CONSTEXPR
bool 416 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
417 {
return __c1 == __c2; }
419 static _GLIBCXX_CONSTEXPR
bool 420 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
421 {
return __c1 < __c2; }
423 static _GLIBCXX17_CONSTEXPR
int 424 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
426 #if __cplusplus >= 201703L 427 if (__builtin_constant_p(__n)
428 && __constant_char_array_p(__s1, __n)
429 && __constant_char_array_p(__s2, __n))
435 return wmemcmp(__s1, __s2, __n);
438 static _GLIBCXX17_CONSTEXPR
size_t 439 length(
const char_type* __s)
441 #if __cplusplus >= 201703L 442 if (__constant_string_p(__s))
449 static _GLIBCXX17_CONSTEXPR
const char_type*
450 find(
const char_type* __s,
size_t __n,
const char_type& __a)
452 #if __cplusplus >= 201703L 453 if (__builtin_constant_p(__n)
454 && __builtin_constant_p(__a)
455 && __constant_char_array_p(__s, __n))
461 return wmemchr(__s, __a, __n);
465 move(char_type* __s1,
const char_type* __s2,
size_t __n)
469 return wmemmove(__s1, __s2, __n);
473 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
477 return wmemcpy(__s1, __s2, __n);
481 assign(char_type* __s,
size_t __n, char_type __a)
485 return wmemset(__s, __a, __n);
488 static _GLIBCXX_CONSTEXPR char_type
489 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
490 {
return char_type(__c); }
492 static _GLIBCXX_CONSTEXPR int_type
493 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
494 {
return int_type(__c); }
496 static _GLIBCXX_CONSTEXPR
bool 497 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
498 {
return __c1 == __c2; }
500 static _GLIBCXX_CONSTEXPR int_type
501 eof() _GLIBCXX_NOEXCEPT
502 {
return static_cast<int_type>(WEOF); }
504 static _GLIBCXX_CONSTEXPR int_type
505 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
506 {
return eq_int_type(__c, eof()) ? 0 : __c; }
508 #endif //_GLIBCXX_USE_WCHAR_T 510 #ifdef _GLIBCXX_USE_CHAR8_T 514 typedef char8_t char_type;
515 typedef unsigned int int_type;
516 typedef u8streampos pos_type;
518 typedef mbstate_t state_type;
520 static _GLIBCXX17_CONSTEXPR
void 521 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
524 static _GLIBCXX_CONSTEXPR
bool 525 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
526 {
return __c1 == __c2; }
528 static _GLIBCXX_CONSTEXPR
bool 529 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
530 {
return __c1 < __c2; }
532 static _GLIBCXX17_CONSTEXPR
int 533 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
535 #if __cplusplus > 201402 536 if (__builtin_constant_p(__n)
537 && __constant_char_array_p(__s1, __n)
538 && __constant_char_array_p(__s2, __n))
543 return __builtin_memcmp(__s1, __s2, __n);
546 static _GLIBCXX17_CONSTEXPR
size_t 547 length(
const char_type* __s)
549 #if __cplusplus > 201402 550 if (__constant_string_p(__s))
554 while (!eq(__s[__i], char_type()))
559 static _GLIBCXX17_CONSTEXPR
const char_type*
560 find(
const char_type* __s,
size_t __n,
const char_type& __a)
562 #if __cplusplus > 201402 563 if (__builtin_constant_p(__n)
564 && __builtin_constant_p(__a)
565 && __constant_char_array_p(__s, __n))
570 return static_cast<const char_type*>(__builtin_memchr(__s, __a, __n));
574 move(char_type* __s1,
const char_type* __s2,
size_t __n)
578 return static_cast<char_type*>(__builtin_memmove(__s1, __s2, __n));
582 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
586 return static_cast<char_type*>(__builtin_memcpy(__s1, __s2, __n));
590 assign(char_type* __s,
size_t __n, char_type __a)
594 return static_cast<char_type*>(__builtin_memset(__s, __a, __n));
597 static _GLIBCXX_CONSTEXPR char_type
598 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
599 {
return char_type(__c); }
601 static _GLIBCXX_CONSTEXPR int_type
602 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
603 {
return int_type(__c); }
605 static _GLIBCXX_CONSTEXPR
bool 606 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
607 {
return __c1 == __c2; }
609 static _GLIBCXX_CONSTEXPR int_type
610 eof() _GLIBCXX_NOEXCEPT
611 {
return static_cast<int_type>(-1); }
613 static _GLIBCXX_CONSTEXPR int_type
614 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
615 {
return eq_int_type(__c, eof()) ? 0 : __c; }
617 #endif //_GLIBCXX_USE_CHAR8_T 619 _GLIBCXX_END_NAMESPACE_VERSION
622 #if __cplusplus >= 201103L 626 namespace std _GLIBCXX_VISIBILITY(default)
628 _GLIBCXX_BEGIN_NAMESPACE_VERSION
631 struct char_traits<char16_t>
633 typedef char16_t char_type;
634 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 635 typedef uint_least16_t int_type;
636 #elif defined __UINT_LEAST16_TYPE__ 637 typedef __UINT_LEAST16_TYPE__ int_type;
639 typedef make_unsigned<char16_t>::type int_type;
643 typedef mbstate_t state_type;
645 static _GLIBCXX17_CONSTEXPR
void 646 assign(char_type& __c1,
const char_type& __c2) noexcept
649 static constexpr
bool 650 eq(
const char_type& __c1,
const char_type& __c2) noexcept
651 {
return __c1 == __c2; }
653 static constexpr
bool 654 lt(
const char_type& __c1,
const char_type& __c2) noexcept
655 {
return __c1 < __c2; }
657 static _GLIBCXX17_CONSTEXPR
int 658 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
660 for (
size_t __i = 0; __i < __n; ++__i)
661 if (lt(__s1[__i], __s2[__i]))
663 else if (lt(__s2[__i], __s1[__i]))
668 static _GLIBCXX17_CONSTEXPR
size_t 669 length(
const char_type* __s)
672 while (!eq(__s[__i], char_type()))
677 static _GLIBCXX17_CONSTEXPR
const char_type*
678 find(
const char_type* __s,
size_t __n,
const char_type& __a)
680 for (
size_t __i = 0; __i < __n; ++__i)
681 if (eq(__s[__i], __a))
687 move(char_type* __s1,
const char_type* __s2,
size_t __n)
691 return (static_cast<char_type*>
692 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
696 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
700 return (static_cast<char_type*>
701 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
705 assign(char_type* __s,
size_t __n, char_type __a)
707 for (
size_t __i = 0; __i < __n; ++__i)
708 assign(__s[__i], __a);
712 static constexpr char_type
713 to_char_type(
const int_type& __c) noexcept
714 {
return char_type(__c); }
716 static constexpr int_type
717 to_int_type(
const char_type& __c) noexcept
718 {
return __c == eof() ? int_type(0xfffd) : int_type(__c); }
720 static constexpr
bool 721 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
722 {
return __c1 == __c2; }
724 static constexpr int_type
726 {
return static_cast<int_type>(-1); }
728 static constexpr int_type
729 not_eof(
const int_type& __c) noexcept
730 {
return eq_int_type(__c, eof()) ? 0 : __c; }
734 struct char_traits<char32_t>
736 typedef char32_t char_type;
737 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 738 typedef uint_least32_t int_type;
739 #elif defined __UINT_LEAST32_TYPE__ 740 typedef __UINT_LEAST32_TYPE__ int_type;
742 typedef make_unsigned<char32_t>::type int_type;
746 typedef mbstate_t state_type;
748 static _GLIBCXX17_CONSTEXPR
void 749 assign(char_type& __c1,
const char_type& __c2) noexcept
752 static constexpr
bool 753 eq(
const char_type& __c1,
const char_type& __c2) noexcept
754 {
return __c1 == __c2; }
756 static constexpr
bool 757 lt(
const char_type& __c1,
const char_type& __c2) noexcept
758 {
return __c1 < __c2; }
760 static _GLIBCXX17_CONSTEXPR
int 761 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
763 for (
size_t __i = 0; __i < __n; ++__i)
764 if (lt(__s1[__i], __s2[__i]))
766 else if (lt(__s2[__i], __s1[__i]))
771 static _GLIBCXX17_CONSTEXPR
size_t 772 length(
const char_type* __s)
775 while (!eq(__s[__i], char_type()))
780 static _GLIBCXX17_CONSTEXPR
const char_type*
781 find(
const char_type* __s,
size_t __n,
const char_type& __a)
783 for (
size_t __i = 0; __i < __n; ++__i)
784 if (eq(__s[__i], __a))
790 move(char_type* __s1,
const char_type* __s2,
size_t __n)
794 return (static_cast<char_type*>
795 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
799 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
803 return (static_cast<char_type*>
804 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
808 assign(char_type* __s,
size_t __n, char_type __a)
810 for (
size_t __i = 0; __i < __n; ++__i)
811 assign(__s[__i], __a);
815 static constexpr char_type
816 to_char_type(
const int_type& __c) noexcept
817 {
return char_type(__c); }
819 static constexpr int_type
820 to_int_type(
const char_type& __c) noexcept
821 {
return int_type(__c); }
823 static constexpr
bool 824 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
825 {
return __c1 == __c2; }
827 static constexpr int_type
829 {
return static_cast<int_type>(-1); }
831 static constexpr int_type
832 not_eof(
const int_type& __c) noexcept
833 {
return eq_int_type(__c, eof()) ? 0 : __c; }
836 _GLIBCXX_END_NAMESPACE_VERSION
841 #endif // _CHAR_TRAITS_H Mapping from character type to associated types.
Basis for explicit traits specializations.
ISO C++ entities toplevel namespace is std.
fpos< mbstate_t > u32streampos
File position for char32_t streams.
GNU extensions for public use.
Base class used to implement std::char_traits.
fpos< mbstate_t > u16streampos
File position for char16_t streams.
_OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
Class representing stream positions.
long long streamoff
Type used by fpos, char_traits<char>, and char_traits<wchar_t>.