This is the mail archive of the 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: user-defined types and basic_string

"Anthony Feick" <> 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('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

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