diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2009-01-13 18:25:36 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2009-01-13 18:25:36 +0000 |
commit | cae70bc9bfa3262f0647b2da6b4df1f89ac07000 (patch) | |
tree | a70a902e35580b2bc001679564b55fbd08cd32c1 | |
parent | e315364d0435472ac9d78080c800aec6e2ac8115 (diff) |
steal some code from gcc 4.2, so that char_traits specializations start with
more default stuff.
as discussed with kettenis, landry, and others.
Allow some gnome stuff (gtk2mm) to compile, and does not break source
compatibility with the standard (well, not more than gcc 4.2 does)
-rw-r--r-- | gnu/lib/libstdc++/libstdc++/include/bits/char_traits.h | 180 | ||||
-rw-r--r-- | gnu/lib/libstdc++/shlib_version | 2 |
2 files changed, 134 insertions, 48 deletions
diff --git a/gnu/lib/libstdc++/libstdc++/include/bits/char_traits.h b/gnu/lib/libstdc++/libstdc++/include/bits/char_traits.h index c42078344d4..1cee9dbc0b8 100644 --- a/gnu/lib/libstdc++/libstdc++/include/bits/char_traits.h +++ b/gnu/lib/libstdc++/libstdc++/include/bits/char_traits.h @@ -45,72 +45,158 @@ #include <cstring> // For memmove, memset, memchr #include <bits/fpos.h> // For streampos -namespace std +namespace __gnu_cxx { - // 21.1 - /** - * @brief Basis for explicit traits specializations. - * - * @note For any given actual character type, this definition is - * probably wrong. - * - * See http://gcc.gnu.org/onlinedocs/libstdc++/21_strings/howto.html#5 - * for advice on how to make use of this class for "unusual" character - * types. - */ - template<class _CharT> + template<typename _CharT> + struct _Char_types + { + typedef unsigned long int_type; + typedef std::streampos pos_type; + typedef std::streamoff off_type; + typedef std::mbstate_t state_type; + }; + + template<typename _CharT> struct char_traits { - typedef _CharT char_type; - // Unsigned as wint_t is unsigned. - typedef unsigned long int_type; - typedef streampos pos_type; - typedef streamoff off_type; - typedef mbstate_t state_type; - - static void - assign(char_type& __c1, const char_type& __c2); + typedef _CharT char_type; + typedef typename _Char_types<_CharT>::int_type int_type; + typedef typename _Char_types<_CharT>::pos_type pos_type; + typedef typename _Char_types<_CharT>::off_type off_type; + typedef typename _Char_types<_CharT>::state_type state_type; - static bool - eq(const char_type& __c1, const char_type& __c2); + static void + assign(char_type& __c1, const char_type& __c2) + { __c1 = __c2; } - static bool - lt(const char_type& __c1, const char_type& __c2); + static bool + eq(const char_type& __c1, const char_type& __c2) + { return __c1 == __c2; } - static int - compare(const char_type* __s1, const char_type* __s2, size_t __n); + static bool + lt(const char_type& __c1, const char_type& __c2) + { return __c1 < __c2; } - static size_t + static int + compare(const char_type* __s1, const char_type* __s2, std::size_t __n); + + static std::size_t length(const char_type* __s); - static const char_type* - find(const char_type* __s, size_t __n, const char_type& __a); + static const char_type* + find(const char_type* __s, std::size_t __n, const char_type& __a); - static char_type* - move(char_type* __s1, const char_type* __s2, size_t __n); + static char_type* + move(char_type* __s1, const char_type* __s2, std::size_t __n); - static char_type* - copy(char_type* __s1, const char_type* __s2, size_t __n); + static char_type* + copy(char_type* __s1, const char_type* __s2, std::size_t __n); - static char_type* - assign(char_type* __s, size_t __n, char_type __a); + static char_type* + assign(char_type* __s, std::size_t __n, char_type __a); - static char_type - to_char_type(const int_type& __c); + static char_type + to_char_type(const int_type& __c) + { return static_cast<char_type>(__c); } - static int_type - to_int_type(const char_type& __c); + static int_type + to_int_type(const char_type& __c) + { return static_cast<int_type>(__c); } - static bool - eq_int_type(const int_type& __c1, const int_type& __c2); + static bool + eq_int_type(const int_type& __c1, const int_type& __c2) + { return __c1 == __c2; } - static int_type - eof(); + static int_type + eof() + { return static_cast<int_type>(EOF); } - static int_type - not_eof(const int_type& __c); + static int_type + not_eof(const int_type& __c) + { return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); } }; + template<typename _CharT> + int + char_traits<_CharT>:: + compare(const char_type* __s1, const char_type* __s2, std::size_t __n) + { + for (std::size_t __i = 0; __i < __n; ++__i) + if (lt(__s1[__i], __s2[__i])) + return -1; + else if (lt(__s2[__i], __s1[__i])) + return 1; + return 0; + } + + template<typename _CharT> + std::size_t + char_traits<_CharT>:: + length(const char_type* __p) + { + std::size_t __i = 0; + while (!eq(__p[__i], char_type())) + ++__i; + return __i; + } + + template<typename _CharT> + const typename char_traits<_CharT>::char_type* + char_traits<_CharT>:: + find(const char_type* __s, std::size_t __n, const char_type& __a) + { + for (std::size_t __i = 0; __i < __n; ++__i) + if (eq(__s[__i], __a)) + return __s + __i; + return 0; + } + + template<typename _CharT> + typename char_traits<_CharT>::char_type* + char_traits<_CharT>:: + move(char_type* __s1, const char_type* __s2, std::size_t __n) + { + return static_cast<_CharT*>(__builtin_memmove(__s1, __s2, + __n * sizeof(char_type))); + } + + template<typename _CharT> + typename char_traits<_CharT>::char_type* + char_traits<_CharT>:: + copy(char_type* __s1, const char_type* __s2, std::size_t __n) + { + // NB: Inline std::copy so no recursive dependencies. + std::copy(__s2, __s2 + __n, __s1); + return __s1; + } + + template<typename _CharT> + typename char_traits<_CharT>::char_type* + char_traits<_CharT>:: + assign(char_type* __s, std::size_t __n, char_type __a) + { + // NB: Inline std::fill_n so no recursive dependencies. + std::fill_n(__s, __n, __a); + return __s; + } +} + +namespace std +{ + // 21.1 + /** + * @brief Basis for explicit traits specializations. + * + * @note For any given actual character type, this definition is + * probably wrong. + * + * See http://gcc.gnu.org/onlinedocs/libstdc++/21_strings/howto.html#5 + * for advice on how to make use of this class for "unusual" character + * types. + */ + template<class _CharT> + struct char_traits: public __gnu_cxx::char_traits<_CharT> + {}; /// 21.1.3.1 char_traits specializations template<> diff --git a/gnu/lib/libstdc++/shlib_version b/gnu/lib/libstdc++/shlib_version index bc1f2f5fd25..b0307472561 100644 --- a/gnu/lib/libstdc++/shlib_version +++ b/gnu/lib/libstdc++/shlib_version @@ -1,2 +1,2 @@ -major=46 +major=47 minor=0 |