36 #ifndef _CHAR_TRAITS_H 
   37 #define _CHAR_TRAITS_H 1 
   39 #pragma GCC system_header 
   45 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
 
   47 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   59   template<
typename _CharT>
 
   62       typedef unsigned long   int_type;
 
   65       typedef std::mbstate_t  state_type;
 
   84   template<
typename _CharT>
 
   87       typedef _CharT                                    char_type;
 
   88       typedef typename _Char_types<_CharT>::int_type    int_type;
 
   90       typedef typename _Char_types<_CharT>::off_type    off_type;
 
   91       typedef typename _Char_types<_CharT>::state_type  state_type;
 
   94       assign(char_type& __c1, 
const char_type& __c2)
 
   97       static _GLIBCXX_CONSTEXPR 
bool 
   98       eq(
const char_type& __c1, 
const char_type& __c2)
 
   99       { 
return __c1 == __c2; }
 
  101       static _GLIBCXX_CONSTEXPR 
bool 
  102       lt(
const char_type& __c1, 
const char_type& __c2)
 
  103       { 
return __c1 < __c2; }
 
  106       compare(
const char_type* __s1, 
const char_type* __s2, std::size_t __n);
 
  109       length(
const char_type* __s);
 
  111       static const char_type*
 
  112       find(
const char_type* __s, std::size_t __n, 
const char_type& __a);
 
  115       move(char_type* __s1, 
const char_type* __s2, std::size_t __n);
 
  118       copy(char_type* __s1, 
const char_type* __s2, std::size_t __n);
 
  121       assign(char_type* __s, std::size_t __n, char_type __a);
 
  123       static _GLIBCXX_CONSTEXPR char_type
 
  124       to_char_type(
const int_type& __c)
 
  125       { 
return static_cast<char_type
>(__c); }
 
  127       static _GLIBCXX_CONSTEXPR int_type
 
  128       to_int_type(
const char_type& __c)
 
  129       { 
return static_cast<int_type
>(__c); }
 
  131       static _GLIBCXX_CONSTEXPR 
bool 
  132       eq_int_type(
const int_type& __c1, 
const int_type& __c2)
 
  133       { 
return __c1 == __c2; }
 
  135       static _GLIBCXX_CONSTEXPR int_type
 
  137       { 
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
 
  139       static _GLIBCXX_CONSTEXPR int_type
 
  140       not_eof(
const int_type& __c)
 
  141       { 
return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); }
 
  144   template<
typename _CharT>
 
  147     compare(
const char_type* __s1, 
const char_type* __s2, std::size_t __n)
 
  149       for (std::size_t __i = 0; __i < __n; ++__i)
 
  150     if (lt(__s1[__i], __s2[__i]))
 
  152     else if (lt(__s2[__i], __s1[__i]))
 
  157   template<
typename _CharT>
 
  159     char_traits<_CharT>::
 
  160     length(
const char_type* __p)
 
  163       while (!eq(__p[__i], char_type()))
 
  168   template<
typename _CharT>
 
  169     const typename char_traits<_CharT>::char_type*
 
  170     char_traits<_CharT>::
 
  171     find(
const char_type* __s, std::size_t __n, 
const char_type& __a)
 
  173       for (std::size_t __i = 0; __i < __n; ++__i)
 
  174         if (eq(__s[__i], __a))
 
  179   template<
typename _CharT>
 
  180     typename char_traits<_CharT>::char_type*
 
  181     char_traits<_CharT>::
 
  182     move(char_type* __s1, 
const char_type* __s2, std::size_t __n)
 
  184       return static_cast<_CharT*
>(__builtin_memmove(__s1, __s2,
 
  185                             __n * 
sizeof(char_type)));
 
  188   template<
typename _CharT>
 
  189     typename char_traits<_CharT>::char_type*
 
  190     char_traits<_CharT>::
 
  191     copy(char_type* __s1, 
const char_type* __s2, std::size_t __n)
 
  194       std::copy(__s2, __s2 + __n, __s1);
 
  198   template<
typename _CharT>
 
  199     typename char_traits<_CharT>::char_type*
 
  200     char_traits<_CharT>::
 
  201     assign(char_type* __s, std::size_t __n, char_type __a)
 
  208 _GLIBCXX_END_NAMESPACE_VERSION
 
  211 namespace std _GLIBCXX_VISIBILITY(default)
 
  213 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
  228   template<
class _CharT>
 
  237       typedef char              char_type;
 
  238       typedef int               int_type;
 
  241       typedef mbstate_t         state_type;
 
  244       assign(char_type& __c1, 
const char_type& __c2)
 
  247       static _GLIBCXX_CONSTEXPR 
bool 
  248       eq(
const char_type& __c1, 
const char_type& __c2)
 
  249       { 
return __c1 == __c2; }
 
  251       static _GLIBCXX_CONSTEXPR 
bool 
  252       lt(
const char_type& __c1, 
const char_type& __c2)
 
  253       { 
return __c1 < __c2; }
 
  256       compare(
const char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  257       { 
return __builtin_memcmp(__s1, __s2, __n); }
 
  260       length(
const char_type* __s)
 
  261       { 
return __builtin_strlen(__s); }
 
  263       static const char_type*
 
  264       find(
const char_type* __s, 
size_t __n, 
const char_type& __a)
 
  265       { 
return static_cast<const char_type*
>(__builtin_memchr(__s, __a, __n)); }
 
  268       move(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  269       { 
return static_cast<char_type*
>(__builtin_memmove(__s1, __s2, __n)); }
 
  272       copy(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  273       { 
return static_cast<char_type*
>(__builtin_memcpy(__s1, __s2, __n)); }
 
  276       assign(char_type* __s, 
size_t __n, char_type __a)
 
  277       { 
return static_cast<char_type*
>(__builtin_memset(__s, __a, __n)); }
 
  279       static _GLIBCXX_CONSTEXPR char_type
 
  280       to_char_type(
const int_type& __c)
 
  281       { 
return static_cast<char_type
>(__c); }
 
  285       static _GLIBCXX_CONSTEXPR int_type
 
  286       to_int_type(
const char_type& __c)
 
  287       { 
return static_cast<int_type
>(
static_cast<unsigned char>(__c)); }
 
  289       static _GLIBCXX_CONSTEXPR 
bool 
  290       eq_int_type(
const int_type& __c1, 
const int_type& __c2)
 
  291       { 
return __c1 == __c2; }
 
  293       static _GLIBCXX_CONSTEXPR int_type
 
  295       { 
return static_cast<int_type
>(_GLIBCXX_STDIO_EOF); }
 
  297       static _GLIBCXX_CONSTEXPR int_type
 
  298       not_eof(
const int_type& __c)
 
  299       { 
return (__c == eof()) ? 0 : __c; }
 
  303 #ifdef _GLIBCXX_USE_WCHAR_T 
  308       typedef wchar_t           char_type;
 
  309       typedef wint_t            int_type;
 
  312       typedef mbstate_t         state_type;
 
  315       assign(char_type& __c1, 
const char_type& __c2)
 
  318       static _GLIBCXX_CONSTEXPR 
bool 
  319       eq(
const char_type& __c1, 
const char_type& __c2)
 
  320       { 
return __c1 == __c2; }
 
  322       static _GLIBCXX_CONSTEXPR 
bool 
  323       lt(
const char_type& __c1, 
const char_type& __c2)
 
  324       { 
return __c1 < __c2; }
 
  327       compare(
const char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  328       { 
return wmemcmp(__s1, __s2, __n); }
 
  331       length(
const char_type* __s)
 
  332       { 
return wcslen(__s); }
 
  334       static const char_type*
 
  335       find(
const char_type* __s, 
size_t __n, 
const char_type& __a)
 
  336       { 
return wmemchr(__s, __a, __n); }
 
  339       move(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  340       { 
return wmemmove(__s1, __s2, __n); }
 
  343       copy(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  344       { 
return wmemcpy(__s1, __s2, __n); }
 
  347       assign(char_type* __s, 
size_t __n, char_type __a)
 
  348       { 
return wmemset(__s, __a, __n); }
 
  350       static _GLIBCXX_CONSTEXPR char_type
 
  351       to_char_type(
const int_type& __c)
 
  352       { 
return char_type(__c); }
 
  354       static _GLIBCXX_CONSTEXPR int_type
 
  355       to_int_type(
const char_type& __c)
 
  356       { 
return int_type(__c); }
 
  358       static _GLIBCXX_CONSTEXPR 
bool 
  359       eq_int_type(
const int_type& __c1, 
const int_type& __c2)
 
  360       { 
return __c1 == __c2; }
 
  362       static _GLIBCXX_CONSTEXPR int_type
 
  364       { 
return static_cast<int_type
>(WEOF); }
 
  366       static _GLIBCXX_CONSTEXPR int_type
 
  367       not_eof(
const int_type& __c)
 
  368       { 
return eq_int_type(__c, eof()) ? 0 : __c; }
 
  370 #endif //_GLIBCXX_USE_WCHAR_T 
  372 _GLIBCXX_END_NAMESPACE_VERSION
 
  375 #if (defined(__GXX_EXPERIMENTAL_CXX0X__) \ 
  376      && defined(_GLIBCXX_USE_C99_STDINT_TR1)) 
  380 namespace std _GLIBCXX_VISIBILITY(default)
 
  382 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
  385     struct char_traits<char16_t>
 
  387       typedef char16_t          char_type;
 
  388       typedef uint_least16_t    int_type;
 
  391       typedef mbstate_t         state_type;
 
  394       assign(char_type& __c1, 
const char_type& __c2)
 
  397       static _GLIBCXX_CONSTEXPR 
bool 
  398       eq(
const char_type& __c1, 
const char_type& __c2)
 
  399       { 
return __c1 == __c2; }
 
  401       static _GLIBCXX_CONSTEXPR 
bool 
  402       lt(
const char_type& __c1, 
const char_type& __c2)
 
  403       { 
return __c1 < __c2; }
 
  406       compare(
const char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  408     for (
size_t __i = 0; __i < __n; ++__i)
 
  409       if (lt(__s1[__i], __s2[__i]))
 
  411       else if (lt(__s2[__i], __s1[__i]))
 
  417       length(
const char_type* __s)
 
  420     while (!eq(__s[__i], char_type()))
 
  425       static const char_type*
 
  426       find(
const char_type* __s, 
size_t __n, 
const char_type& __a)
 
  428     for (
size_t __i = 0; __i < __n; ++__i)
 
  429       if (eq(__s[__i], __a))
 
  435       move(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  437     return (static_cast<char_type*>
 
  438         (__builtin_memmove(__s1, __s2, __n * 
sizeof(char_type))));
 
  442       copy(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  444     return (static_cast<char_type*>
 
  445         (__builtin_memcpy(__s1, __s2, __n * 
sizeof(char_type))));
 
  449       assign(char_type* __s, 
size_t __n, char_type __a)
 
  451     for (
size_t __i = 0; __i < __n; ++__i)
 
  452       assign(__s[__i], __a);
 
  456       static _GLIBCXX_CONSTEXPR char_type
 
  457       to_char_type(
const int_type& __c)
 
  458       { 
return char_type(__c); }
 
  460       static _GLIBCXX_CONSTEXPR int_type
 
  461       to_int_type(
const char_type& __c)
 
  462       { 
return int_type(__c); }
 
  464       static _GLIBCXX_CONSTEXPR 
bool 
  465       eq_int_type(
const int_type& __c1, 
const int_type& __c2)
 
  466       { 
return __c1 == __c2; }
 
  468       static _GLIBCXX_CONSTEXPR int_type
 
  470       { 
return static_cast<int_type
>(-1); }
 
  472       static _GLIBCXX_CONSTEXPR int_type
 
  473       not_eof(
const int_type& __c)
 
  474       { 
return eq_int_type(__c, eof()) ? 0 : __c; }
 
  478     struct char_traits<char32_t>
 
  480       typedef char32_t          char_type;
 
  481       typedef uint_least32_t    int_type;
 
  484       typedef mbstate_t         state_type;
 
  487       assign(char_type& __c1, 
const char_type& __c2)
 
  490       static _GLIBCXX_CONSTEXPR 
bool 
  491       eq(
const char_type& __c1, 
const char_type& __c2)
 
  492       { 
return __c1 == __c2; }
 
  494       static _GLIBCXX_CONSTEXPR 
bool 
  495       lt(
const char_type& __c1, 
const char_type& __c2)
 
  496       { 
return __c1 < __c2; }
 
  499       compare(
const char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  501     for (
size_t __i = 0; __i < __n; ++__i)
 
  502       if (lt(__s1[__i], __s2[__i]))
 
  504       else if (lt(__s2[__i], __s1[__i]))
 
  510       length(
const char_type* __s)
 
  513     while (!eq(__s[__i], char_type()))
 
  518       static const char_type*
 
  519       find(
const char_type* __s, 
size_t __n, 
const char_type& __a)
 
  521     for (
size_t __i = 0; __i < __n; ++__i)
 
  522       if (eq(__s[__i], __a))
 
  528       move(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  530     return (static_cast<char_type*>
 
  531         (__builtin_memmove(__s1, __s2, __n * 
sizeof(char_type))));
 
  535       copy(char_type* __s1, 
const char_type* __s2, 
size_t __n)
 
  537     return (static_cast<char_type*>
 
  538         (__builtin_memcpy(__s1, __s2, __n * 
sizeof(char_type))));
 
  542       assign(char_type* __s, 
size_t __n, char_type __a)
 
  544     for (
size_t __i = 0; __i < __n; ++__i)
 
  545       assign(__s[__i], __a);
 
  549       static _GLIBCXX_CONSTEXPR char_type
 
  550       to_char_type(
const int_type& __c)
 
  551       { 
return char_type(__c); }
 
  553       static _GLIBCXX_CONSTEXPR int_type
 
  554       to_int_type(
const char_type& __c)
 
  555       { 
return int_type(__c); }
 
  557       static _GLIBCXX_CONSTEXPR 
bool 
  558       eq_int_type(
const int_type& __c1, 
const int_type& __c2)
 
  559       { 
return __c1 == __c2; }
 
  561       static _GLIBCXX_CONSTEXPR int_type
 
  563       { 
return static_cast<int_type
>(-1); }
 
  565       static _GLIBCXX_CONSTEXPR int_type
 
  566       not_eof(
const int_type& __c)
 
  567       { 
return eq_int_type(__c, eof()) ? 0 : __c; }
 
  570 _GLIBCXX_END_NAMESPACE_VERSION
 
  575 #endif // _CHAR_TRAITS_H 
Mapping from character type to associated types. 
 
Basis for explicit traits specializations. 
 
long long streamoff
Type used by fpos, char_traits<char>, and char_traits<wchar_t>. 
 
Base class used to implement std::char_traits. 
 
Class representing stream positions. 
 
fpos< mbstate_t > u16streampos
File position for char16_t streams. 
 
_OI fill_n(_OI __first, _Size __n, const _Tp &__value)
Fills the range [first,first+n) with copies of value. 
 
fpos< mbstate_t > u32streampos
File position for char32_t streams.