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
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*
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*
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*
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*
205 assign(char_type* __s, std::size_t __n, char_type __a)
208 std::fill_n(__s, __n, __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 _GLIBCXX_END_NAMESPACE_VERSION
513 #if __cplusplus >= 201103L 517 namespace std _GLIBCXX_VISIBILITY(default)
519 _GLIBCXX_BEGIN_NAMESPACE_VERSION
524 typedef char16_t char_type;
525 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 526 typedef uint_least16_t int_type;
527 #elif defined __UINT_LEAST16_TYPE__ 528 typedef __UINT_LEAST16_TYPE__ int_type;
530 typedef make_unsigned<char16_t>::type int_type;
534 typedef mbstate_t state_type;
536 static _GLIBCXX17_CONSTEXPR
void 537 assign(char_type& __c1,
const char_type& __c2) noexcept
540 static constexpr
bool 541 eq(
const char_type& __c1,
const char_type& __c2) noexcept
542 {
return __c1 == __c2; }
544 static constexpr
bool 545 lt(
const char_type& __c1,
const char_type& __c2) noexcept
546 {
return __c1 < __c2; }
548 static _GLIBCXX17_CONSTEXPR
int 549 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
551 for (
size_t __i = 0; __i < __n; ++__i)
552 if (lt(__s1[__i], __s2[__i]))
554 else if (lt(__s2[__i], __s1[__i]))
559 static _GLIBCXX17_CONSTEXPR
size_t 560 length(
const char_type* __s)
563 while (!eq(__s[__i], char_type()))
568 static _GLIBCXX17_CONSTEXPR
const char_type*
569 find(
const char_type* __s,
size_t __n,
const char_type& __a)
571 for (
size_t __i = 0; __i < __n; ++__i)
572 if (eq(__s[__i], __a))
578 move(char_type* __s1,
const char_type* __s2,
size_t __n)
582 return (static_cast<char_type*>
583 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
587 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
591 return (static_cast<char_type*>
592 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
596 assign(char_type* __s,
size_t __n, char_type __a)
598 for (
size_t __i = 0; __i < __n; ++__i)
599 assign(__s[__i], __a);
603 static constexpr char_type
604 to_char_type(
const int_type& __c) noexcept
605 {
return char_type(__c); }
607 static constexpr int_type
608 to_int_type(
const char_type& __c) noexcept
609 {
return __c == eof() ? int_type(0xfffd) : int_type(__c); }
611 static constexpr
bool 612 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
613 {
return __c1 == __c2; }
615 static constexpr int_type
617 {
return static_cast<int_type
>(-1); }
619 static constexpr int_type
620 not_eof(
const int_type& __c) noexcept
621 {
return eq_int_type(__c, eof()) ? 0 : __c; }
627 typedef char32_t char_type;
628 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 629 typedef uint_least32_t int_type;
630 #elif defined __UINT_LEAST32_TYPE__ 631 typedef __UINT_LEAST32_TYPE__ int_type;
633 typedef make_unsigned<char32_t>::type int_type;
637 typedef mbstate_t state_type;
639 static _GLIBCXX17_CONSTEXPR
void 640 assign(char_type& __c1,
const char_type& __c2) noexcept
643 static constexpr
bool 644 eq(
const char_type& __c1,
const char_type& __c2) noexcept
645 {
return __c1 == __c2; }
647 static constexpr
bool 648 lt(
const char_type& __c1,
const char_type& __c2) noexcept
649 {
return __c1 < __c2; }
651 static _GLIBCXX17_CONSTEXPR
int 652 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
654 for (
size_t __i = 0; __i < __n; ++__i)
655 if (lt(__s1[__i], __s2[__i]))
657 else if (lt(__s2[__i], __s1[__i]))
662 static _GLIBCXX17_CONSTEXPR
size_t 663 length(
const char_type* __s)
666 while (!eq(__s[__i], char_type()))
671 static _GLIBCXX17_CONSTEXPR
const char_type*
672 find(
const char_type* __s,
size_t __n,
const char_type& __a)
674 for (
size_t __i = 0; __i < __n; ++__i)
675 if (eq(__s[__i], __a))
681 move(char_type* __s1,
const char_type* __s2,
size_t __n)
685 return (static_cast<char_type*>
686 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
690 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
694 return (static_cast<char_type*>
695 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
699 assign(char_type* __s,
size_t __n, char_type __a)
701 for (
size_t __i = 0; __i < __n; ++__i)
702 assign(__s[__i], __a);
706 static constexpr char_type
707 to_char_type(
const int_type& __c) noexcept
708 {
return char_type(__c); }
710 static constexpr int_type
711 to_int_type(
const char_type& __c) noexcept
712 {
return int_type(__c); }
714 static constexpr
bool 715 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
716 {
return __c1 == __c2; }
718 static constexpr int_type
720 {
return static_cast<int_type
>(-1); }
722 static constexpr int_type
723 not_eof(
const int_type& __c) noexcept
724 {
return eq_int_type(__c, eof()) ? 0 : __c; }
727 _GLIBCXX_END_NAMESPACE_VERSION
732 #endif // _CHAR_TRAITS_H Mapping from character type to associated types.
Basis for explicit traits specializations.
ISO C++ entities toplevel namespace is std.
GNU extensions for public use.
long long streamoff
Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
Class representing stream positions.
Base class used to implement std::char_traits.