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 while (__builtin_constant_p(*__s) && *__s)
235 return __builtin_constant_p(*__s);
246 template<
typename _CharT>
247 static _GLIBCXX_ALWAYS_INLINE constexpr
bool 248 __constant_char_array_p(
const _CharT* __a,
size_t __n)
251 while (__builtin_constant_p(__a[__i]) && __i < __n)
270 template<
class _CharT>
279 typedef char char_type;
280 typedef int int_type;
283 typedef mbstate_t state_type;
285 static _GLIBCXX17_CONSTEXPR
void 286 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
289 static _GLIBCXX_CONSTEXPR
bool 290 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
291 {
return __c1 == __c2; }
293 static _GLIBCXX_CONSTEXPR
bool 294 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
297 return (static_cast<unsigned char>(__c1)
298 < static_cast<unsigned char>(__c2));
301 static _GLIBCXX17_CONSTEXPR
int 302 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
304 #if __cplusplus >= 201703L 305 if (__builtin_constant_p(__n)
306 && __constant_char_array_p(__s1, __n)
307 && __constant_char_array_p(__s2, __n))
312 return __builtin_memcmp(__s1, __s2, __n);
315 static _GLIBCXX17_CONSTEXPR
size_t 316 length(
const char_type* __s)
318 #if __cplusplus >= 201703L 319 if (__constant_string_p(__s))
322 return __builtin_strlen(__s);
325 static _GLIBCXX17_CONSTEXPR
const char_type*
326 find(
const char_type* __s,
size_t __n,
const char_type& __a)
328 #if __cplusplus >= 201703L 329 if (__builtin_constant_p(__n)
330 && __builtin_constant_p(__a)
331 && __constant_char_array_p(__s, __n))
336 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
340 move(char_type* __s1,
const char_type* __s2,
size_t __n)
344 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
348 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
352 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
356 assign(char_type* __s,
size_t __n, char_type __a)
360 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
363 static _GLIBCXX_CONSTEXPR char_type
364 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
365 {
return static_cast<char_type
>(__c); }
369 static _GLIBCXX_CONSTEXPR int_type
370 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
371 {
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
373 static _GLIBCXX_CONSTEXPR
bool 374 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
375 {
return __c1 == __c2; }
377 static _GLIBCXX_CONSTEXPR int_type
378 eof() _GLIBCXX_NOEXCEPT
379 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
381 static _GLIBCXX_CONSTEXPR int_type
382 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
383 {
return (__c == eof()) ? 0 : __c; }
387 #ifdef _GLIBCXX_USE_WCHAR_T 392 typedef wchar_t char_type;
393 typedef wint_t int_type;
396 typedef mbstate_t state_type;
398 static _GLIBCXX17_CONSTEXPR
void 399 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
402 static _GLIBCXX_CONSTEXPR
bool 403 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
404 {
return __c1 == __c2; }
406 static _GLIBCXX_CONSTEXPR
bool 407 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
408 {
return __c1 < __c2; }
410 static _GLIBCXX17_CONSTEXPR
int 411 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
413 #if __cplusplus >= 201703L 414 if (__builtin_constant_p(__n)
415 && __constant_char_array_p(__s1, __n)
416 && __constant_char_array_p(__s2, __n))
422 return wmemcmp(__s1, __s2, __n);
425 static _GLIBCXX17_CONSTEXPR
size_t 426 length(
const char_type* __s)
428 #if __cplusplus >= 201703L 429 if (__constant_string_p(__s))
436 static _GLIBCXX17_CONSTEXPR
const char_type*
437 find(
const char_type* __s,
size_t __n,
const char_type& __a)
439 #if __cplusplus >= 201703L 440 if (__builtin_constant_p(__n)
441 && __builtin_constant_p(__a)
442 && __constant_char_array_p(__s, __n))
448 return wmemchr(__s, __a, __n);
452 move(char_type* __s1,
const char_type* __s2,
size_t __n)
456 return wmemmove(__s1, __s2, __n);
460 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
464 return wmemcpy(__s1, __s2, __n);
468 assign(char_type* __s,
size_t __n, char_type __a)
472 return wmemset(__s, __a, __n);
475 static _GLIBCXX_CONSTEXPR char_type
476 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
477 {
return char_type(__c); }
479 static _GLIBCXX_CONSTEXPR int_type
480 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
481 {
return int_type(__c); }
483 static _GLIBCXX_CONSTEXPR
bool 484 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
485 {
return __c1 == __c2; }
487 static _GLIBCXX_CONSTEXPR int_type
488 eof() _GLIBCXX_NOEXCEPT
489 {
return static_cast<int_type
>(WEOF); }
491 static _GLIBCXX_CONSTEXPR int_type
492 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
493 {
return eq_int_type(__c, eof()) ? 0 : __c; }
495 #endif //_GLIBCXX_USE_WCHAR_T 497 _GLIBCXX_END_NAMESPACE_VERSION
500 #if __cplusplus >= 201103L 504 namespace std _GLIBCXX_VISIBILITY(default)
506 _GLIBCXX_BEGIN_NAMESPACE_VERSION
511 typedef char16_t char_type;
512 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 513 typedef uint_least16_t int_type;
514 #elif defined __UINT_LEAST16_TYPE__ 515 typedef __UINT_LEAST16_TYPE__ int_type;
517 typedef make_unsigned<char16_t>::type int_type;
521 typedef mbstate_t state_type;
523 static _GLIBCXX17_CONSTEXPR
void 524 assign(char_type& __c1,
const char_type& __c2) noexcept
527 static constexpr
bool 528 eq(
const char_type& __c1,
const char_type& __c2) noexcept
529 {
return __c1 == __c2; }
531 static constexpr
bool 532 lt(
const char_type& __c1,
const char_type& __c2) noexcept
533 {
return __c1 < __c2; }
535 static _GLIBCXX17_CONSTEXPR
int 536 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
538 for (
size_t __i = 0; __i < __n; ++__i)
539 if (lt(__s1[__i], __s2[__i]))
541 else if (lt(__s2[__i], __s1[__i]))
546 static _GLIBCXX17_CONSTEXPR
size_t 547 length(
const char_type* __s)
550 while (!eq(__s[__i], char_type()))
555 static _GLIBCXX17_CONSTEXPR
const char_type*
556 find(
const char_type* __s,
size_t __n,
const char_type& __a)
558 for (
size_t __i = 0; __i < __n; ++__i)
559 if (eq(__s[__i], __a))
565 move(char_type* __s1,
const char_type* __s2,
size_t __n)
569 return (static_cast<char_type*>
570 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
574 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
578 return (static_cast<char_type*>
579 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
583 assign(char_type* __s,
size_t __n, char_type __a)
585 for (
size_t __i = 0; __i < __n; ++__i)
586 assign(__s[__i], __a);
590 static constexpr char_type
591 to_char_type(
const int_type& __c) noexcept
592 {
return char_type(__c); }
594 static constexpr int_type
595 to_int_type(
const char_type& __c) noexcept
596 {
return __c == eof() ? int_type(0xfffd) : int_type(__c); }
598 static constexpr
bool 599 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
600 {
return __c1 == __c2; }
602 static constexpr int_type
604 {
return static_cast<int_type
>(-1); }
606 static constexpr int_type
607 not_eof(
const int_type& __c) noexcept
608 {
return eq_int_type(__c, eof()) ? 0 : __c; }
614 typedef char32_t char_type;
615 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 616 typedef uint_least32_t int_type;
617 #elif defined __UINT_LEAST32_TYPE__ 618 typedef __UINT_LEAST32_TYPE__ int_type;
620 typedef make_unsigned<char32_t>::type int_type;
624 typedef mbstate_t state_type;
626 static _GLIBCXX17_CONSTEXPR
void 627 assign(char_type& __c1,
const char_type& __c2) noexcept
630 static constexpr
bool 631 eq(
const char_type& __c1,
const char_type& __c2) noexcept
632 {
return __c1 == __c2; }
634 static constexpr
bool 635 lt(
const char_type& __c1,
const char_type& __c2) noexcept
636 {
return __c1 < __c2; }
638 static _GLIBCXX17_CONSTEXPR
int 639 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
641 for (
size_t __i = 0; __i < __n; ++__i)
642 if (lt(__s1[__i], __s2[__i]))
644 else if (lt(__s2[__i], __s1[__i]))
649 static _GLIBCXX17_CONSTEXPR
size_t 650 length(
const char_type* __s)
653 while (!eq(__s[__i], char_type()))
658 static _GLIBCXX17_CONSTEXPR
const char_type*
659 find(
const char_type* __s,
size_t __n,
const char_type& __a)
661 for (
size_t __i = 0; __i < __n; ++__i)
662 if (eq(__s[__i], __a))
668 move(char_type* __s1,
const char_type* __s2,
size_t __n)
672 return (static_cast<char_type*>
673 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
677 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
681 return (static_cast<char_type*>
682 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
686 assign(char_type* __s,
size_t __n, char_type __a)
688 for (
size_t __i = 0; __i < __n; ++__i)
689 assign(__s[__i], __a);
693 static constexpr char_type
694 to_char_type(
const int_type& __c) noexcept
695 {
return char_type(__c); }
697 static constexpr int_type
698 to_int_type(
const char_type& __c) noexcept
699 {
return int_type(__c); }
701 static constexpr
bool 702 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
703 {
return __c1 == __c2; }
705 static constexpr int_type
707 {
return static_cast<int_type
>(-1); }
709 static constexpr int_type
710 not_eof(
const int_type& __c) noexcept
711 {
return eq_int_type(__c, eof()) ? 0 : __c; }
714 _GLIBCXX_END_NAMESPACE_VERSION
719 #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.