user-defined types and basic_string
Gabriel Dos Reis
gdr@integrable-solutions.net
Thu Aug 29 09:45:00 GMT 2002
"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
More information about the Libstdc++
mailing list