This is the mail archive of the
mailing list for the libstdc++ project.
Re: user-defined types and basic_string
- From: Benjamin Kosnik <bkoz at redhat dot com>
- To: "Anthony Feick" <afeick at hotmail dot com>
- Cc: gdr at integrable-solutions dot net, libstdc++ at gcc dot gnu dot org
- Date: Thu, 29 Aug 2002 09:31:05 -0700
- Subject: Re: user-defined types and basic_string
- Organization: Red Hat / San Francisco
- References: <F62OpvzxrnDuFIQaj9i00004fca@hotmail.com>
> I was unable to implicitly create characters from integers :
> basic_string<char_type> theString;
> No amount of casting was able to fix this, and constructors in character<T>
> will not work because then it isn't Plain Old Data (POD??). With a
> constructor it can't be used in a union, among other problems.
Right. This is what is lame about user-defined types being aggregates.
> I ended up not using templates at all, instead just defining char_traits as:
> namespace std
> struct char_traits<unsigned short>
> typedef unsigned short char_type;
> Unless you know of an 'elegant' way to go from an int to a character, this
> will have to do.
What you are doing (I'm assuming specializing std::char_traits<int>,
instantating std::basic_string<int>), is undefined but I believe it
should be defined to be something useful.