This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: user-defined types and basic_string
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: "Anthony Feick" <afeick at hotmail dot com>
- Cc: bkoz at redhat dot com, libstdc++ at gcc dot gnu dot org
- Date: 29 Aug 2002 18:40:33 +0200
- Subject: Re: user-defined types and basic_string
- Organization: Integrable Solutions
- References: <F62OpvzxrnDuFIQaj9i00004fca@hotmail.com>
"Anthony Feick" <afeick@hotmail.com> writes:
| Thank you for posting the example for an "unsigned short" basic_string. I
| didn't get a chance to get back to this until yesterday, but had some
| problems with the final example you posted.
|
| I was unable to implicitly create characters from integers :
inline character<unsigned short>
as_character(unsigned short c)
{
character<unsigned short> r = { c };
return c;
}
With inlining and the named return value optimization, that should
cost nothing.
| basic_string<char_type> theString;
| theString.append(0x20);
theString.append(as_character(0x20));
| theString.append('o');
theString.append(as_character('o'));
while the syntax isn't the best of the world, it does highlight what
is going on.
| 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??).
Just use what constructors are: functions that construct an object
from given argument :-) (see above).
| I ended up not using templates at all, instead just defining char_traits as:
As noted in the discussion, that may or may not work with other
implementations or future versions of V3. Only you know how portable
you want your constructs.
-- Gaby