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)
186 return static_cast<_CharT*
>(__builtin_memmove(__s1, __s2,
187 __n *
sizeof(char_type)));
190 template<
typename _CharT>
191 typename char_traits<_CharT>::char_type*
193 copy(char_type* __s1,
const char_type* __s2, std::size_t __n)
196 std::copy(__s2, __s2 + __n, __s1);
200 template<
typename _CharT>
201 typename char_traits<_CharT>::char_type*
203 assign(char_type* __s, std::size_t __n, char_type __a)
206 std::fill_n(__s, __n, __a);
210 _GLIBCXX_END_NAMESPACE_VERSION
213 namespace std _GLIBCXX_VISIBILITY(default)
215 _GLIBCXX_BEGIN_NAMESPACE_VERSION
217 #if __cplusplus >= 201703L 218 #define __cpp_lib_constexpr_char_traits 201611 227 template<
typename _CharT>
228 static _GLIBCXX_ALWAYS_INLINE constexpr
bool 229 __constant_string_p(
const _CharT* __s)
231 while (__builtin_constant_p(*__s) && *__s)
233 return __builtin_constant_p(*__s);
244 template<
typename _CharT>
245 static _GLIBCXX_ALWAYS_INLINE constexpr
bool 246 __constant_char_array_p(
const _CharT* __a,
size_t __n)
249 while (__builtin_constant_p(__a[__i]) && __i < __n)
268 template<
class _CharT>
277 typedef char char_type;
278 typedef int int_type;
281 typedef mbstate_t state_type;
283 static _GLIBCXX17_CONSTEXPR
void 284 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
287 static _GLIBCXX_CONSTEXPR
bool 288 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
289 {
return __c1 == __c2; }
291 static _GLIBCXX_CONSTEXPR
bool 292 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
295 return (static_cast<unsigned char>(__c1)
296 < static_cast<unsigned char>(__c2));
299 static _GLIBCXX17_CONSTEXPR
int 300 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
302 #if __cplusplus >= 201703L 303 if (__builtin_constant_p(__n)
304 && __constant_char_array_p(__s1, __n)
305 && __constant_char_array_p(__s2, __n))
310 return __builtin_memcmp(__s1, __s2, __n);
313 static _GLIBCXX17_CONSTEXPR
size_t 314 length(
const char_type* __s)
316 #if __cplusplus >= 201703L 317 if (__constant_string_p(__s))
320 return __builtin_strlen(__s);
323 static _GLIBCXX17_CONSTEXPR
const char_type*
324 find(
const char_type* __s,
size_t __n,
const char_type& __a)
326 #if __cplusplus >= 201703L 327 if (__builtin_constant_p(__n)
328 && __builtin_constant_p(__a)
329 && __constant_char_array_p(__s, __n))
334 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
338 move(char_type* __s1,
const char_type* __s2,
size_t __n)
342 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
346 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
350 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
354 assign(char_type* __s,
size_t __n, char_type __a)
358 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
361 static _GLIBCXX_CONSTEXPR char_type
362 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
363 {
return static_cast<char_type
>(__c); }
367 static _GLIBCXX_CONSTEXPR int_type
368 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
369 {
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
371 static _GLIBCXX_CONSTEXPR
bool 372 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
373 {
return __c1 == __c2; }
375 static _GLIBCXX_CONSTEXPR int_type
376 eof() _GLIBCXX_NOEXCEPT
377 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
379 static _GLIBCXX_CONSTEXPR int_type
380 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
381 {
return (__c == eof()) ? 0 : __c; }
385 #ifdef _GLIBCXX_USE_WCHAR_T 390 typedef wchar_t char_type;
391 typedef wint_t int_type;
394 typedef mbstate_t state_type;
396 static _GLIBCXX17_CONSTEXPR
void 397 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
400 static _GLIBCXX_CONSTEXPR
bool 401 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
402 {
return __c1 == __c2; }
404 static _GLIBCXX_CONSTEXPR
bool 405 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
406 {
return __c1 < __c2; }
408 static _GLIBCXX17_CONSTEXPR
int 409 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
411 #if __cplusplus >= 201703L 412 if (__builtin_constant_p(__n)
413 && __constant_char_array_p(__s1, __n)
414 && __constant_char_array_p(__s2, __n))
420 return wmemcmp(__s1, __s2, __n);
423 static _GLIBCXX17_CONSTEXPR
size_t 424 length(
const char_type* __s)
426 #if __cplusplus >= 201703L 427 if (__constant_string_p(__s))
434 static _GLIBCXX17_CONSTEXPR
const char_type*
435 find(
const char_type* __s,
size_t __n,
const char_type& __a)
437 #if __cplusplus >= 201703L 438 if (__builtin_constant_p(__n)
439 && __builtin_constant_p(__a)
440 && __constant_char_array_p(__s, __n))
446 return wmemchr(__s, __a, __n);
450 move(char_type* __s1,
const char_type* __s2,
size_t __n)
454 return wmemmove(__s1, __s2, __n);
458 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
462 return wmemcpy(__s1, __s2, __n);
466 assign(char_type* __s,
size_t __n, char_type __a)
470 return wmemset(__s, __a, __n);
473 static _GLIBCXX_CONSTEXPR char_type
474 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
475 {
return char_type(__c); }
477 static _GLIBCXX_CONSTEXPR int_type
478 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
479 {
return int_type(__c); }
481 static _GLIBCXX_CONSTEXPR
bool 482 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
483 {
return __c1 == __c2; }
485 static _GLIBCXX_CONSTEXPR int_type
486 eof() _GLIBCXX_NOEXCEPT
487 {
return static_cast<int_type
>(WEOF); }
489 static _GLIBCXX_CONSTEXPR int_type
490 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
491 {
return eq_int_type(__c, eof()) ? 0 : __c; }
493 #endif //_GLIBCXX_USE_WCHAR_T 495 _GLIBCXX_END_NAMESPACE_VERSION
498 #if __cplusplus >= 201103L 502 namespace std _GLIBCXX_VISIBILITY(default)
504 _GLIBCXX_BEGIN_NAMESPACE_VERSION
509 typedef char16_t char_type;
510 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 511 typedef uint_least16_t int_type;
512 #elif defined __UINT_LEAST16_TYPE__ 513 typedef __UINT_LEAST16_TYPE__ int_type;
515 typedef make_unsigned<char16_t>::type int_type;
519 typedef mbstate_t state_type;
521 static _GLIBCXX17_CONSTEXPR
void 522 assign(char_type& __c1,
const char_type& __c2) noexcept
525 static constexpr
bool 526 eq(
const char_type& __c1,
const char_type& __c2) noexcept
527 {
return __c1 == __c2; }
529 static constexpr
bool 530 lt(
const char_type& __c1,
const char_type& __c2) noexcept
531 {
return __c1 < __c2; }
533 static _GLIBCXX17_CONSTEXPR
int 534 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
536 for (
size_t __i = 0; __i < __n; ++__i)
537 if (lt(__s1[__i], __s2[__i]))
539 else if (lt(__s2[__i], __s1[__i]))
544 static _GLIBCXX17_CONSTEXPR
size_t 545 length(
const char_type* __s)
548 while (!eq(__s[__i], char_type()))
553 static _GLIBCXX17_CONSTEXPR
const char_type*
554 find(
const char_type* __s,
size_t __n,
const char_type& __a)
556 for (
size_t __i = 0; __i < __n; ++__i)
557 if (eq(__s[__i], __a))
563 move(char_type* __s1,
const char_type* __s2,
size_t __n)
567 return (static_cast<char_type*>
568 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
572 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
576 return (static_cast<char_type*>
577 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
581 assign(char_type* __s,
size_t __n, char_type __a)
583 for (
size_t __i = 0; __i < __n; ++__i)
584 assign(__s[__i], __a);
588 static constexpr char_type
589 to_char_type(
const int_type& __c) noexcept
590 {
return char_type(__c); }
592 static constexpr int_type
593 to_int_type(
const char_type& __c) noexcept
594 {
return __c == eof() ? int_type(0xfffd) : int_type(__c); }
596 static constexpr
bool 597 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
598 {
return __c1 == __c2; }
600 static constexpr int_type
602 {
return static_cast<int_type
>(-1); }
604 static constexpr int_type
605 not_eof(
const int_type& __c) noexcept
606 {
return eq_int_type(__c, eof()) ? 0 : __c; }
612 typedef char32_t char_type;
613 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 614 typedef uint_least32_t int_type;
615 #elif defined __UINT_LEAST32_TYPE__ 616 typedef __UINT_LEAST32_TYPE__ int_type;
618 typedef make_unsigned<char32_t>::type int_type;
622 typedef mbstate_t state_type;
624 static _GLIBCXX17_CONSTEXPR
void 625 assign(char_type& __c1,
const char_type& __c2) noexcept
628 static constexpr
bool 629 eq(
const char_type& __c1,
const char_type& __c2) noexcept
630 {
return __c1 == __c2; }
632 static constexpr
bool 633 lt(
const char_type& __c1,
const char_type& __c2) noexcept
634 {
return __c1 < __c2; }
636 static _GLIBCXX17_CONSTEXPR
int 637 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
639 for (
size_t __i = 0; __i < __n; ++__i)
640 if (lt(__s1[__i], __s2[__i]))
642 else if (lt(__s2[__i], __s1[__i]))
647 static _GLIBCXX17_CONSTEXPR
size_t 648 length(
const char_type* __s)
651 while (!eq(__s[__i], char_type()))
656 static _GLIBCXX17_CONSTEXPR
const char_type*
657 find(
const char_type* __s,
size_t __n,
const char_type& __a)
659 for (
size_t __i = 0; __i < __n; ++__i)
660 if (eq(__s[__i], __a))
666 move(char_type* __s1,
const char_type* __s2,
size_t __n)
670 return (static_cast<char_type*>
671 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
675 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
679 return (static_cast<char_type*>
680 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
684 assign(char_type* __s,
size_t __n, char_type __a)
686 for (
size_t __i = 0; __i < __n; ++__i)
687 assign(__s[__i], __a);
691 static constexpr char_type
692 to_char_type(
const int_type& __c) noexcept
693 {
return char_type(__c); }
695 static constexpr int_type
696 to_int_type(
const char_type& __c) noexcept
697 {
return int_type(__c); }
699 static constexpr
bool 700 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
701 {
return __c1 == __c2; }
703 static constexpr int_type
705 {
return static_cast<int_type
>(-1); }
707 static constexpr int_type
708 not_eof(
const int_type& __c) noexcept
709 {
return eq_int_type(__c, eof()) ? 0 : __c; }
712 _GLIBCXX_END_NAMESPACE_VERSION
717 #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.