This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: basic_streambuf / locale::ctype problems


"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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]