This is the mail archive of the libstdc++@gcc.gnu.org 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: [RFC] Money_get::do_get appends?!?


On Sun, Feb 03, 2002 at 11:54:12PM +0100, Paolo Carlini wrote:
> Nathan Myers wrote:
> 
> >Almost.  If it fails, it must leave the string unchanged.
>
> You mean: I can call erase at the beginning and then, if it fails during 
> the parsing, I must remember to call erase once more before bailing out???

Sorry, worse than that.  If the user passes in "Golgafrincham" the user 
has to get back either "123" or "Golgafrincham".  You can avoid an
allocation by parsing characters into an array on the stack and
expanding to secondary storage only if it's exceeded, and then copying 
into the string storage.  If it helps any you can make it (or a separate 
function, for the purpose) a friend of basic_string<>::_Rep.  Or you
can use basic_string<>::swap.

Nathan Myers
ncm at cantrip dot org


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