34 #ifndef _CHAR_TRAITS_H 
   35 #define _CHAR_TRAITS_H 1 
   37 #pragma GCC system_header 
   43 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
 
   45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   57   template<
typename _CharT>
 
   60       typedef unsigned long   int_type;
 
   63       typedef std::mbstate_t  state_type;
 
   82   template<
typename _CharT>
 
   85       typedef _CharT                                    char_type;
 
   86       typedef typename _Char_types<_CharT>::int_type    int_type;
 
   88       typedef typename _Char_types<_CharT>::off_type    off_type;
 
   89       typedef typename _Char_types<_CharT>::state_type  state_type;
 
   92       assign(char_type& __c1, 
const char_type& __c2)
 
   95       static _GLIBCXX_CONSTEXPR 
bool 
   96       eq(
const char_type& __c1, 
const char_type& __c2)
 
   97       { 
return __c1 == __c2; }
 
   99       static _GLIBCXX_CONSTEXPR 
bool 
  100       lt(
const char_type& __c1, 
const char_type& __c2)
 
  101       { 
return __c1 < __c2; }
 
  104       compare(
const char_type* __s1, 
const char_type* __s2, std::size_t __n);
 
  107       length(
const char_type* __s);
 
  109       static const char_type*
 
  110       find(
const char_type* __s, std::size_t __n, 
const char_type& __a);
 
  113       move(char_type* __s1, 
const char_type* __s2, std::size_t __n);
 
  116       copy(char_type* __s1, 
const char_type* __s2, std::size_t __n);
 
  119       assign(char_type* __s, std::size_t __n, char_type __a);
 
  121       static _GLIBCXX_CONSTEXPR char_type
 
  122       to_char_type(
const int_type& __c)
 
  123       { 
return static_cast<char_type
>(__c); }
 
  125       static _GLIBCXX_CONSTEXPR int_type
 
  126       to_int_type(
const char_type& __c)
 
  127       { 
return static_cast<int_type
>(__c); }
 
  129       static _GLIBCXX_CONSTEXPR 
bool 
  130       eq_int_type(
const int_type& __c1, 
const int_type& __c2)
 
  131       { 
return __c1 == __c2; }
 
  133       static _GLIBCXX_CONSTEXPR int_type
 
  135       { 
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
 
  137       static _GLIBCXX_CONSTEXPR int_type
 
  138       not_eof(
const int_type& __c)
 
  139       { 
return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
 
  142   template<
typename _CharT>
 
  145     compare(
const char_type* __s1, 
const char_type* __s2, std::size_t __n)
 
  147       for (std::size_t __i = 0; __i < __n; ++__i)
 
  148     if (lt(__s1[__i], __s2[__i]))
 
  150     else if (lt(__s2[__i], __s1[__i]))
 
  155   template<
typename _CharT>
 
  157     char_traits<_CharT>::
 
  158     length(
const char_type* __p)
 
  161       while (!eq(__p[__i], char_type()))
 
  166   template<
typename _CharT>
 
  167     const typename char_traits<_CharT>::char_type*
 
  168     char_traits<_CharT>::
 
  169     find(
const char_type* __s, std::size_t __n, 
const char_type& __a)
 
  171       for (std::size_t __i = 0; __i < __n; ++__i)
 
  172         if (eq(__s[__i], __a))
 
  177   template<
typename _CharT>
 
  178     typename char_traits<_CharT>::char_type*
 
  180     move(char_type* __s1, 
const char_type* __s2, std::size_t __n)
 
  182       return static_cast<_CharT*
>(__builtin_memmove(__s1, __s2,
 
  183                             __n * 
sizeof(char_type)));
 
  186   template<
typename _CharT>
 
  187     typename char_traits<_CharT>::char_type*
 
  188     char_traits<_CharT>::
 
  189     copy(char_type* __s1, 
const char_type* __s2, std::size_t __n)
 
  192       std::copy(__s2, __s2 + __n, __s1);
 
  196   template<
typename _CharT>
 
  197     typename char_traits<_CharT>::char_type*
 
  198     char_traits<_CharT>::
 
  199     assign(char_type* __s, std::size_t __n, char_type __a)
 
  206 _GLIBCXX_END_NAMESPACE_VERSION
 
  209 namespace std _GLIBCXX_VISIBILITY(default)
 
  211 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
  226   template<
class _CharT>
 
  235       typedef char              char_type;
 
  236       typedef int               int_type;
 
  239       typedef mbstate_t         state_type;
 
  242       assign(char_type& __c1, 
const char_type& __c2) _GLIBCXX_NOEXCEPT
 
  245       static _GLIBCXX_CONSTEXPR 
bool 
  246       eq(
const char_type& __c1, 
const char_type& __c2) _GLIBCXX_NOEXCEPT
 
  247       { 
return __c1 == __c2; }
 
  249       static _GLIBCXX_CONSTEXPR 
bool 
  250       lt(
const char_type& __c1, 
const char_type& __c2) _GLIBCXX_NOEXCEPT
 
  253     return (static_cast<unsigned char>(__c1)
 
  254         < static_cast<unsigned char>(__c2));
 
  258       compare(
const char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  259       { 
return __builtin_memcmp(__s1, __s2, __n); }
 
  262       length(
const char_type* __s)
 
  263       { 
return __builtin_strlen(__s); }
 
  265       static const char_type*
 
  266       find(
const char_type* __s, 
size_t __n, 
const char_type& __a)
 
  267       { 
return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n)); }
 
  270       move(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  271       { 
return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n)); }
 
  274       copy(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  275       { 
return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n)); }
 
  278       assign(char_type* __s, 
size_t __n, char_type __a)
 
  279       { 
return static_cast<char_type*
>(__builtin_memset(__s, __a, __n)); }
 
  281       static _GLIBCXX_CONSTEXPR char_type
 
  282       to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
 
  283       { 
return static_cast<char_type
>(__c); }
 
  287       static _GLIBCXX_CONSTEXPR int_type
 
  288       to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
 
  289       { 
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
 
  291       static _GLIBCXX_CONSTEXPR 
bool 
  292       eq_int_type(
const int_type& __c1, 
const int_type& __c2) _GLIBCXX_NOEXCEPT
 
  293       { 
return __c1 == __c2; }
 
  295       static _GLIBCXX_CONSTEXPR int_type
 
  296       eof() _GLIBCXX_NOEXCEPT
 
  297       { 
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
 
  299       static _GLIBCXX_CONSTEXPR int_type
 
  300       not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
 
  301       { 
return (__c == eof()) ? 0 : __c; }
 
  305 #ifdef _GLIBCXX_USE_WCHAR_T 
  310       typedef wchar_t           char_type;
 
  311       typedef wint_t            int_type;
 
  314       typedef mbstate_t         state_type;
 
  317       assign(char_type& __c1, 
const char_type& __c2) _GLIBCXX_NOEXCEPT
 
  320       static _GLIBCXX_CONSTEXPR 
bool 
  321       eq(
const char_type& __c1, 
const char_type& __c2) _GLIBCXX_NOEXCEPT
 
  322       { 
return __c1 == __c2; }
 
  324       static _GLIBCXX_CONSTEXPR 
bool 
  325       lt(
const char_type& __c1, 
const char_type& __c2) _GLIBCXX_NOEXCEPT
 
  326       { 
return __c1 < __c2; }
 
  329       compare(
const char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  330       { 
return wmemcmp(__s1, __s2, __n); }
 
  333       length(
const char_type* __s)
 
  334       { 
return wcslen(__s); }
 
  336       static const char_type*
 
  337       find(
const char_type* __s, 
size_t __n, 
const char_type& __a)
 
  338       { 
return wmemchr(__s, __a, __n); }
 
  341       move(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  342       { 
return wmemmove(__s1, __s2, __n); }
 
  345       copy(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  346       { 
return wmemcpy(__s1, __s2, __n); }
 
  349       assign(char_type* __s, 
size_t __n, char_type __a)
 
  350       { 
return wmemset(__s, __a, __n); }
 
  352       static _GLIBCXX_CONSTEXPR char_type
 
  353       to_char_type(
const int_type& __c) _GLIBCXX_NOEXCEPT
 
  354       { 
return char_type(__c); }
 
  356       static _GLIBCXX_CONSTEXPR int_type
 
  357       to_int_type(
const char_type& __c) _GLIBCXX_NOEXCEPT
 
  358       { 
return int_type(__c); }
 
  360       static _GLIBCXX_CONSTEXPR 
bool 
  361       eq_int_type(
const int_type& __c1, 
const int_type& __c2) _GLIBCXX_NOEXCEPT
 
  362       { 
return __c1 == __c2; }
 
  364       static _GLIBCXX_CONSTEXPR int_type
 
  365       eof() _GLIBCXX_NOEXCEPT
 
  366       { 
return static_cast<int_type
>(WEOF); }
 
  368       static _GLIBCXX_CONSTEXPR int_type
 
  369       not_eof(
const int_type& __c) _GLIBCXX_NOEXCEPT
 
  370       { 
return eq_int_type(__c, eof()) ? 0 : __c; }
 
  372 #endif //_GLIBCXX_USE_WCHAR_T 
  374 _GLIBCXX_END_NAMESPACE_VERSION
 
  377 #if ((__cplusplus >= 201103L) \ 
  378      && defined(_GLIBCXX_USE_C99_STDINT_TR1)) 
  382 namespace std _GLIBCXX_VISIBILITY(default)
 
  384 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
  387     struct char_traits<char16_t>
 
  389       typedef char16_t          char_type;
 
  390       typedef uint_least16_t    int_type;
 
  393       typedef mbstate_t         state_type;
 
  396       assign(char_type& __c1, 
const char_type& __c2) noexcept
 
  399       static constexpr 
bool 
  400       eq(
const char_type& __c1, 
const char_type& __c2) noexcept
 
  401       { 
return __c1 == __c2; }
 
  403       static constexpr 
bool 
  404       lt(
const char_type& __c1, 
const char_type& __c2) noexcept
 
  405       { 
return __c1 < __c2; }
 
  408       compare(
const char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  410     for (
size_t __i = 0; __i < __n; ++__i)
 
  411       if (lt(__s1[__i], __s2[__i]))
 
  413       else if (lt(__s2[__i], __s1[__i]))
 
  419       length(
const char_type* __s)
 
  422     while (!eq(__s[__i], char_type()))
 
  427       static const char_type*
 
  428       find(
const char_type* __s, 
size_t __n, 
const char_type& __a)
 
  430     for (
size_t __i = 0; __i < __n; ++__i)
 
  431       if (eq(__s[__i], __a))
 
  437       move(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  439     return (static_cast<char_type*>
 
  440         (__builtin_memmove(__s1, __s2, __n * 
sizeof(char_type))));
 
  444       copy(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  446     return (static_cast<char_type*>
 
  447         (__builtin_memcpy(__s1, __s2, __n * 
sizeof(char_type))));
 
  451       assign(char_type* __s, 
size_t __n, char_type __a)
 
  453     for (
size_t __i = 0; __i < __n; ++__i)
 
  454       assign(__s[__i], __a);
 
  458       static constexpr char_type
 
  459       to_char_type(
const int_type& __c) noexcept
 
  460       { 
return char_type(__c); }
 
  462       static constexpr int_type
 
  463       to_int_type(
const char_type& __c) noexcept
 
  464       { 
return int_type(__c); }
 
  466       static constexpr 
bool 
  467       eq_int_type(
const int_type& __c1, 
const int_type& __c2) noexcept
 
  468       { 
return __c1 == __c2; }
 
  470       static constexpr int_type
 
  472       { 
return static_cast<int_type
>(-1); }
 
  474       static constexpr int_type
 
  475       not_eof(
const int_type& __c) noexcept
 
  476       { 
return eq_int_type(__c, eof()) ? 0 : __c; }
 
  480     struct char_traits<char32_t>
 
  482       typedef char32_t          char_type;
 
  483       typedef uint_least32_t    int_type;
 
  486       typedef mbstate_t         state_type;
 
  489       assign(char_type& __c1, 
const char_type& __c2) noexcept
 
  492       static constexpr 
bool 
  493       eq(
const char_type& __c1, 
const char_type& __c2) noexcept
 
  494       { 
return __c1 == __c2; }
 
  496       static constexpr 
bool 
  497       lt(
const char_type& __c1, 
const char_type& __c2) noexcept
 
  498       { 
return __c1 < __c2; }
 
  501       compare(
const char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  503     for (
size_t __i = 0; __i < __n; ++__i)
 
  504       if (lt(__s1[__i], __s2[__i]))
 
  506       else if (lt(__s2[__i], __s1[__i]))
 
  512       length(
const char_type* __s)
 
  515     while (!eq(__s[__i], char_type()))
 
  520       static const char_type*
 
  521       find(
const char_type* __s, 
size_t __n, 
const char_type& __a)
 
  523     for (
size_t __i = 0; __i < __n; ++__i)
 
  524       if (eq(__s[__i], __a))
 
  530       move(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  532     return (static_cast<char_type*>
 
  533         (__builtin_memmove(__s1, __s2, __n * 
sizeof(char_type))));
 
  537       copy(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  539     return (static_cast<char_type*>
 
  540         (__builtin_memcpy(__s1, __s2, __n * 
sizeof(char_type))));
 
  544       assign(char_type* __s, 
size_t __n, char_type __a)
 
  546     for (
size_t __i = 0; __i < __n; ++__i)
 
  547       assign(__s[__i], __a);
 
  551       static constexpr char_type
 
  552       to_char_type(
const int_type& __c) noexcept
 
  553       { 
return char_type(__c); }
 
  555       static constexpr int_type
 
  556       to_int_type(
const char_type& __c) noexcept
 
  557       { 
return int_type(__c); }
 
  559       static constexpr 
bool 
  560       eq_int_type(
const int_type& __c1, 
const int_type& __c2) noexcept
 
  561       { 
return __c1 == __c2; }
 
  563       static constexpr int_type
 
  565       { 
return static_cast<int_type
>(-1); }
 
  567       static constexpr int_type
 
  568       not_eof(
const int_type& __c) noexcept
 
  569       { 
return eq_int_type(__c, eof()) ? 0 : __c; }
 
  572 _GLIBCXX_END_NAMESPACE_VERSION
 
  577 #endif // _CHAR_TRAITS_H 
Mapping from character type to associated types. 
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue. 
GNU extensions for public use. 
long long streamoff
Type used by fpos, char_traits, and char_traits. 
ISO C++ entities toplevel namespace is std. 
Base class used to implement std::char_traits. 
Basis for explicit traits specializations. 
_OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value. 
Class representing stream positions. 
fpos< mbstate_t > u16streampos
File position for char16_t streams. 
fpos< mbstate_t > u32streampos
File position for char32_t streams.