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 > 201402 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 (__i < __n && __builtin_constant_p(__a[__i]))
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 > 201402 305 if (__builtin_constant_p(__n)
306 && __constant_char_array_p(__s1, __n)
307 && __constant_char_array_p(__s2, __n))
309 for (
size_t __i = 0; __i < __n; ++__i)
310 if (lt(__s1[__i], __s2[__i]))
312 else if (lt(__s2[__i], __s1[__i]))
319 return __builtin_memcmp(__s1, __s2, __n);
322 static _GLIBCXX17_CONSTEXPR
size_t 323 length(
const char_type* __s)
325 #if __cplusplus > 201402 326 if (__constant_string_p(__s))
329 return __builtin_strlen(__s);
332 static _GLIBCXX17_CONSTEXPR
const char_type*
333 find(
const char_type* __s,
size_t __n,
const char_type& __a)
335 #if __cplusplus > 201402 336 if (__builtin_constant_p(__n)
337 && __builtin_constant_p(__a)
338 && __constant_char_array_p(__s, __n))
343 return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n));
347 move(char_type* __s1,
const char_type* __s2,
size_t __n)
351 return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n));
355 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
359 return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n));
363 assign(char_type* __s,
size_t __n, char_type __a)
367 return static_cast<char_type*
>(__builtin_memset(__s, __a, __n));
370 static _GLIBCXX_CONSTEXPR char_type
371 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
372 {
return static_cast<char_type
>(__c); }
376 static _GLIBCXX_CONSTEXPR int_type
377 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
378 {
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
380 static _GLIBCXX_CONSTEXPR
bool 381 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
382 {
return __c1 == __c2; }
384 static _GLIBCXX_CONSTEXPR int_type
385 eof() _GLIBCXX_NOEXCEPT
386 {
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
388 static _GLIBCXX_CONSTEXPR int_type
389 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
390 {
return (__c == eof()) ? 0 : __c; }
394 #ifdef _GLIBCXX_USE_WCHAR_T 399 typedef wchar_t char_type;
400 typedef wint_t int_type;
403 typedef mbstate_t state_type;
405 static _GLIBCXX17_CONSTEXPR
void 406 assign(char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
409 static _GLIBCXX_CONSTEXPR
bool 410 eq(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
411 {
return __c1 == __c2; }
413 static _GLIBCXX_CONSTEXPR
bool 414 lt(
const char_type& __c1,
const char_type& __c2) _GLIBCXX_NOEXCEPT
415 {
return __c1 < __c2; }
417 static _GLIBCXX17_CONSTEXPR
int 418 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
420 #if __cplusplus > 201402 421 if (__builtin_constant_p(__n)
422 && __constant_char_array_p(__s1, __n)
423 && __constant_char_array_p(__s2, __n))
429 return wmemcmp(__s1, __s2, __n);
432 static _GLIBCXX17_CONSTEXPR
size_t 433 length(
const char_type* __s)
435 #if __cplusplus > 201402 436 if (__constant_string_p(__s))
443 static _GLIBCXX17_CONSTEXPR
const char_type*
444 find(
const char_type* __s,
size_t __n,
const char_type& __a)
446 #if __cplusplus > 201402 447 if (__builtin_constant_p(__n)
448 && __builtin_constant_p(__a)
449 && __constant_char_array_p(__s, __n))
455 return wmemchr(__s, __a, __n);
459 move(char_type* __s1,
const char_type* __s2,
size_t __n)
463 return wmemmove(__s1, __s2, __n);
467 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
471 return wmemcpy(__s1, __s2, __n);
475 assign(char_type* __s,
size_t __n, char_type __a)
479 return wmemset(__s, __a, __n);
482 static _GLIBCXX_CONSTEXPR char_type
483 to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
484 {
return char_type(__c); }
486 static _GLIBCXX_CONSTEXPR int_type
487 to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
488 {
return int_type(__c); }
490 static _GLIBCXX_CONSTEXPR
bool 491 eq_int_type(
const int_type& __c1,
const int_type& __c2) _GLIBCXX_NOEXCEPT
492 {
return __c1 == __c2; }
494 static _GLIBCXX_CONSTEXPR int_type
495 eof() _GLIBCXX_NOEXCEPT
496 {
return static_cast<int_type
>(WEOF); }
498 static _GLIBCXX_CONSTEXPR int_type
499 not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
500 {
return eq_int_type(__c, eof()) ? 0 : __c; }
502 #endif //_GLIBCXX_USE_WCHAR_T 504 _GLIBCXX_END_NAMESPACE_VERSION
507 #if ((__cplusplus >= 201103L) \ 508 && defined(_GLIBCXX_USE_C99_STDINT_TR1)) 512 namespace std _GLIBCXX_VISIBILITY(default)
514 _GLIBCXX_BEGIN_NAMESPACE_VERSION
517 struct char_traits<char16_t>
519 typedef char16_t char_type;
520 typedef uint_least16_t int_type;
523 typedef mbstate_t state_type;
525 static _GLIBCXX17_CONSTEXPR
void 526 assign(char_type& __c1,
const char_type& __c2) noexcept
529 static constexpr
bool 530 eq(
const char_type& __c1,
const char_type& __c2) noexcept
531 {
return __c1 == __c2; }
533 static constexpr
bool 534 lt(
const char_type& __c1,
const char_type& __c2) noexcept
535 {
return __c1 < __c2; }
537 static _GLIBCXX17_CONSTEXPR
int 538 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
540 for (
size_t __i = 0; __i < __n; ++__i)
541 if (lt(__s1[__i], __s2[__i]))
543 else if (lt(__s2[__i], __s1[__i]))
548 static _GLIBCXX17_CONSTEXPR
size_t 549 length(
const char_type* __s)
552 while (!eq(__s[__i], char_type()))
557 static _GLIBCXX17_CONSTEXPR
const char_type*
558 find(
const char_type* __s,
size_t __n,
const char_type& __a)
560 for (
size_t __i = 0; __i < __n; ++__i)
561 if (eq(__s[__i], __a))
567 move(char_type* __s1,
const char_type* __s2,
size_t __n)
571 return (static_cast<char_type*>
572 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
576 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
580 return (static_cast<char_type*>
581 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
585 assign(char_type* __s,
size_t __n, char_type __a)
587 for (
size_t __i = 0; __i < __n; ++__i)
588 assign(__s[__i], __a);
592 static constexpr char_type
593 to_char_type(
const int_type& __c) noexcept
594 {
return char_type(__c); }
596 static constexpr int_type
597 to_int_type(
const char_type& __c) noexcept
598 {
return __c == eof() ? int_type(0xfffd) : int_type(__c); }
600 static constexpr
bool 601 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
602 {
return __c1 == __c2; }
604 static constexpr int_type
606 {
return static_cast<int_type
>(-1); }
608 static constexpr int_type
609 not_eof(
const int_type& __c) noexcept
610 {
return eq_int_type(__c, eof()) ? 0 : __c; }
614 struct char_traits<char32_t>
616 typedef char32_t char_type;
617 typedef uint_least32_t int_type;
620 typedef mbstate_t state_type;
622 static _GLIBCXX17_CONSTEXPR
void 623 assign(char_type& __c1,
const char_type& __c2) noexcept
626 static constexpr
bool 627 eq(
const char_type& __c1,
const char_type& __c2) noexcept
628 {
return __c1 == __c2; }
630 static constexpr
bool 631 lt(
const char_type& __c1,
const char_type& __c2) noexcept
632 {
return __c1 < __c2; }
634 static _GLIBCXX17_CONSTEXPR
int 635 compare(
const char_type* __s1,
const char_type* __s2,
size_t __n)
637 for (
size_t __i = 0; __i < __n; ++__i)
638 if (lt(__s1[__i], __s2[__i]))
640 else if (lt(__s2[__i], __s1[__i]))
645 static _GLIBCXX17_CONSTEXPR
size_t 646 length(
const char_type* __s)
649 while (!eq(__s[__i], char_type()))
654 static _GLIBCXX17_CONSTEXPR
const char_type*
655 find(
const char_type* __s,
size_t __n,
const char_type& __a)
657 for (
size_t __i = 0; __i < __n; ++__i)
658 if (eq(__s[__i], __a))
664 move(char_type* __s1,
const char_type* __s2,
size_t __n)
668 return (static_cast<char_type*>
669 (__builtin_memmove(__s1, __s2, __n *
sizeof(char_type))));
673 copy(char_type* __s1,
const char_type* __s2,
size_t __n)
677 return (static_cast<char_type*>
678 (__builtin_memcpy(__s1, __s2, __n *
sizeof(char_type))));
682 assign(char_type* __s,
size_t __n, char_type __a)
684 for (
size_t __i = 0; __i < __n; ++__i)
685 assign(__s[__i], __a);
689 static constexpr char_type
690 to_char_type(
const int_type& __c) noexcept
691 {
return char_type(__c); }
693 static constexpr int_type
694 to_int_type(
const char_type& __c) noexcept
695 {
return int_type(__c); }
697 static constexpr
bool 698 eq_int_type(
const int_type& __c1,
const int_type& __c2) noexcept
699 {
return __c1 == __c2; }
701 static constexpr int_type
703 {
return static_cast<int_type
>(-1); }
705 static constexpr int_type
706 not_eof(
const int_type& __c) noexcept
707 {
return eq_int_type(__c, eof()) ? 0 : __c; }
710 _GLIBCXX_END_NAMESPACE_VERSION
715 #endif // _CHAR_TRAITS_H fpos< mbstate_t > u32streampos
File position for char32_t streams.
Class representing stream positions.
Base class used to implement std::char_traits.
Mapping from character type to associated types.
GNU extensions for public use.
_OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value.
ISO C++ entities toplevel namespace is std.
fpos< mbstate_t > u16streampos
File position for char16_t streams.
long long streamoff
Type used by fpos, char_traits<char>, and char_traits<wchar_t>.
Basis for explicit traits specializations.