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 (__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))
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)
343 #if __cplusplus >= 201703L 344 if (__builtin_constant_p(__n)
345 && __builtin_constant_p(__a)
346 && __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)
428 #if __cplusplus >= 201703L 429 if (__builtin_constant_p(__n)
430 && __constant_char_array_p(__s1, __n)
431 && __constant_char_array_p(__s2, __n))
434 return wmemcmp(__s1, __s2, __n);
437 static _GLIBCXX17_CONSTEXPR
size_t 438 length(
const char_type* __s)
440 #if __cplusplus >= 201703L 441 if (__constant_string_p(__s))
447 static _GLIBCXX17_CONSTEXPR
const char_type*
448 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))
458 return wmemchr(__s, __a, __n);
462 move(char_type* __s1,
const char_type* __s2,
size_t __n)
466 return wmemmove(__s1, __s2, __n);
470 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
474 return wmemcpy(__s1, __s2, __n);
478 assign(char_type* __s,
size_t __n, char_type __a)
482 return wmemset(__s, __a, __n);
485 static _GLIBCXX_CONSTEXPR char_type
486 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
487 {
return char_type(__c); }
489 static _GLIBCXX_CONSTEXPR int_type
490 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
491 {
return int_type(__c); }
493 static _GLIBCXX_CONSTEXPR
bool 494 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
495 {
return __c1 == __c2; }
497 static _GLIBCXX_CONSTEXPR int_type
498 eof() _GLIBCXX_NOEXCEPT
499 {
return static_cast<int_type
>(WEOF); }
501 static _GLIBCXX_CONSTEXPR int_type
502 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
503 {
return eq_int_type(__c, eof()) ? 0 : __c; }
505 #endif //_GLIBCXX_USE_WCHAR_T 507 #ifdef _GLIBCXX_USE_CHAR8_T 511 typedef char8_t char_type;
512 typedef unsigned int int_type;
513 typedef u8streampos pos_type;
515 typedef mbstate_t state_type;
517 static _GLIBCXX17_CONSTEXPR
void 518 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
521 static _GLIBCXX_CONSTEXPR
bool 522 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
523 {
return __c1 == __c2; }
525 static _GLIBCXX_CONSTEXPR
bool 526 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
527 {
return __c1 < __c2; }
529 static _GLIBCXX17_CONSTEXPR
int 530 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
534 #if __cplusplus > 201402 535 if (__builtin_constant_p(__n)
536 && __constant_char_array_p(__s1, __n)
537 && __constant_char_array_p(__s2, __n))
540 return __builtin_memcmp(__s1, __s2, __n);
543 static _GLIBCXX17_CONSTEXPR
size_t 544 length(
const char_type* __s)
546 #if __cplusplus > 201402 547 if (__constant_string_p(__s))
551 while (!eq(__s[__i], char_type()))
556 static _GLIBCXX17_CONSTEXPR
const char_type*
557 find(
const char_type* __s,
size_t __n,
const char_type& __a)
561 #if __cplusplus > 201402 562 if (__builtin_constant_p(__n)
563 && __builtin_constant_p(__a)
564 && __constant_char_array_p(__s, __n))
567 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
571 move(char_type* __s1,
const char_type* __s2,
size_t __n)
575 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
579 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
583 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
587 assign(char_type* __s,
size_t __n, char_type __a)
591 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
594 static _GLIBCXX_CONSTEXPR char_type
595 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
596 {
return char_type(__c); }
598 static _GLIBCXX_CONSTEXPR int_type
599 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
600 {
return int_type(__c); }
602 static _GLIBCXX_CONSTEXPR
bool 603 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
604 {
return __c1 == __c2; }
606 static _GLIBCXX_CONSTEXPR int_type
607 eof() _GLIBCXX_NOEXCEPT
608 {
return static_cast<int_type
>(-1); }
610 static _GLIBCXX_CONSTEXPR int_type
611 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
612 {
return eq_int_type(__c, eof()) ? 0 : __c; }
614 #endif //_GLIBCXX_USE_CHAR8_T 616 _GLIBCXX_END_NAMESPACE_VERSION
619 #if __cplusplus >= 201103L 623 namespace std _GLIBCXX_VISIBILITY(default)
625 _GLIBCXX_BEGIN_NAMESPACE_VERSION
628 struct char_traits<char16_t>
630 typedef char16_t char_type;
631 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 632 typedef uint_least16_t int_type;
633 #elif defined __UINT_LEAST16_TYPE__ 634 typedef __UINT_LEAST16_TYPE__ int_type;
636 typedef make_unsigned<char16_t>::type int_type;
640 typedef mbstate_t state_type;
642 static _GLIBCXX17_CONSTEXPR
void 643 assign(char_type& __c1,
const char_type& __c2) noexcept
646 static constexpr
bool 647 eq(
const char_type& __c1,
const char_type& __c2) noexcept
648 {
return __c1 == __c2; }
650 static constexpr
bool 651 lt(
const char_type& __c1,
const char_type& __c2) noexcept
652 {
return __c1 < __c2; }
654 static _GLIBCXX17_CONSTEXPR
int 655 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
657 for (
size_t __i = 0; __i < __n; ++__i)
658 if (lt(__s1[__i], __s2[__i]))
660 else if (lt(__s2[__i], __s1[__i]))
665 static _GLIBCXX17_CONSTEXPR
size_t 666 length(
const char_type* __s)
669 while (!eq(__s[__i], char_type()))
674 static _GLIBCXX17_CONSTEXPR
const char_type*
675 find(
const char_type* __s,
size_t __n,
const char_type& __a)
677 for (
size_t __i = 0; __i < __n; ++__i)
678 if (eq(__s[__i], __a))
684 move(char_type* __s1,
const char_type* __s2,
size_t __n)
688 return (static_cast<char_type*>
689 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
693 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
697 return (static_cast<char_type*>
698 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
702 assign(char_type* __s,
size_t __n, char_type __a)
704 for (
size_t __i = 0; __i < __n; ++__i)
705 assign(__s[__i], __a);
709 static constexpr char_type
710 to_char_type(
const int_type& __c) noexcept
711 {
return char_type(__c); }
713 static constexpr int_type
714 to_int_type(
const char_type& __c) noexcept
715 {
return __c == eof() ? int_type(0xfffd) : int_type(__c); }
717 static constexpr
bool 718 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
719 {
return __c1 == __c2; }
721 static constexpr int_type
723 {
return static_cast<int_type
>(-1); }
725 static constexpr int_type
726 not_eof(
const int_type& __c) noexcept
727 {
return eq_int_type(__c, eof()) ? 0 : __c; }
731 struct char_traits<char32_t>
733 typedef char32_t char_type;
734 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 735 typedef uint_least32_t int_type;
736 #elif defined __UINT_LEAST32_TYPE__ 737 typedef __UINT_LEAST32_TYPE__ int_type;
739 typedef make_unsigned<char32_t>::type int_type;
743 typedef mbstate_t state_type;
745 static _GLIBCXX17_CONSTEXPR
void 746 assign(char_type& __c1,
const char_type& __c2) noexcept
749 static constexpr
bool 750 eq(
const char_type& __c1,
const char_type& __c2) noexcept
751 {
return __c1 == __c2; }
753 static constexpr
bool 754 lt(
const char_type& __c1,
const char_type& __c2) noexcept
755 {
return __c1 < __c2; }
757 static _GLIBCXX17_CONSTEXPR
int 758 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
760 for (
size_t __i = 0; __i < __n; ++__i)
761 if (lt(__s1[__i], __s2[__i]))
763 else if (lt(__s2[__i], __s1[__i]))
768 static _GLIBCXX17_CONSTEXPR
size_t 769 length(
const char_type* __s)
772 while (!eq(__s[__i], char_type()))
777 static _GLIBCXX17_CONSTEXPR
const char_type*
778 find(
const char_type* __s,
size_t __n,
const char_type& __a)
780 for (
size_t __i = 0; __i < __n; ++__i)
781 if (eq(__s[__i], __a))
787 move(char_type* __s1,
const char_type* __s2,
size_t __n)
791 return (static_cast<char_type*>
792 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
796 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
800 return (static_cast<char_type*>
801 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
805 assign(char_type* __s,
size_t __n, char_type __a)
807 for (
size_t __i = 0; __i < __n; ++__i)
808 assign(__s[__i], __a);
812 static constexpr char_type
813 to_char_type(
const int_type& __c) noexcept
814 {
return char_type(__c); }
816 static constexpr int_type
817 to_int_type(
const char_type& __c) noexcept
818 {
return int_type(__c); }
820 static constexpr
bool 821 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
822 {
return __c1 == __c2; }
824 static constexpr int_type
826 {
return static_cast<int_type
>(-1); }
828 static constexpr int_type
829 not_eof(
const int_type& __c) noexcept
830 {
return eq_int_type(__c, eof()) ? 0 : __c; }
833 _GLIBCXX_END_NAMESPACE_VERSION
838 #endif // _CHAR_TRAITS_H Class representing stream positions.
Base class used to implement std::char_traits.
ISO C++ entities toplevel namespace is std.
fpos< mbstate_t > u32streampos
File position for char32_t streams.
Mapping from character type to associated types.
long long streamoff
Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
_OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
GNU extensions for public use.
Basis for explicit traits specializations.
fpos< mbstate_t > u16streampos
File position for char16_t streams.