This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: basic_streambuf / locale::ctype problems
- From: Gabriel Dos Reis <gdr at codesourcery dot com>
- To: jack_reeves at bleading-edge dot com
- Cc: libstdc++ at gcc dot gnu dot org
- Date: 29 Jun 2002 20:30:10 +0200
- Subject: Re: basic_streambuf / locale::ctype problems
- Organization: CodeSourcery, LLC
- References: <F151bgIK78ULGKv96el000018ff@hotmail.com>
"Jack Reeves" <jackw_reeves@hotmail.com> writes:
[...]
| 2. Adding an explicit specialization for char_traits<int> yields:
| ------
| #include <string>
| #include <sstream>
| template<> std::char_traits<int> { /* … */ }
| int main() {
| std::basic_stringstream<int> test;
| }
| -----
| This should compile, but may still result in undefined behavior. In
| particular, the specialization is likely to contain
| typedef unsigned long int_type;
| After all, this is what the default implementation provided. Unfortunately,
| the Standard is clear that char_traits<>::int_type is suppose to be
| something “wider” than the char_type. In particular, it must be able to
| contain all values of char_type, plus a unique eof value.
No, that is not what the standard says. It says that int_type shall
be able to represent all *valid* characters converted from the
corresponding char_type (21.1.2/2).
The key word here is "valid". Not just because char_type is "int"
means that all int values are valid characters. Some may not be.
If you want all int values to be valid characters then you ought to
find an int_type larger.
And you can't make an explicit specialization named
std::char_traits<int> anyway. So the issue is moot. Or you have to
change the specs as currently defined.
-- Gaby