Specializations of std::char_traits
Nathan Myers
ncm-nospam@cantrip.org
Wed Jul 16 18:11:00 GMT 2003
On Tue, Jul 15, 2003 at 04:39:04PM -0700, Matt Austern wrote:
> We've received several complaints from customers who noticed that
> std::char_traits<int> (or long, or signed char, or unsigned short, or
> whatever) used to be defined but isn't defined anymore.
>
> Now, just to be obvious, I realize that
> - The C++ standard doesn't say there should be any specializations
> other than char and wchar_t
> - In general there's no way to define all of the members of
> std::char_traits for an arbitrary type. There's no good way to say
> what char_traits<T>::int_type should be, for example.
As I recall, the standard requires a default definition of
char_traits<T> for any T. (I recall the vote in favor, which I
opposed, if mildly.) Therefore, there should be no need for
specializations for any but the char and wchar_t case. Furthermore,
users are not allowed to specialize those, and the default
definitions are probably not right. std::basic_string<int> should
work, but users should not expect to get std::filebuf<int> without
surprises.
Users who need to define their own character types should use a struct
type they control, e.g. "struct MyChar { int c; };".
Nathan Myers
ncm-nospam@cantrip.org
More information about the Libstdc++
mailing list