[Patch/RFC] Improve (maybe ;) basic_stringbuf::overflow

Nathan Myers ncm-nospam@cantrip.org
Thu May 1 21:03:00 GMT 2003


On Thu, May 01, 2003 at 10:38:35PM +0200, Paolo Carlini wrote:
> However, I'm not sure the standard guarantees that
> swap exchanges also the capacities: I rely on that
> property of v3 basic_string implementation.

Is your concern about specializations of string on user character 
types?

Since string::swap is required to run in constant time, it can't 
copy N characters.  That almost implies the storage has to be the 
same, and thus, implicitly, the capacity as well.  However, it is 
possible to implement string so that it stores small strings 
differently from larger ones, and does swap differently, still 
meeting the constant-time constraint while copying.  Hmm, 
string::reserve() is cheap when capacity is already >= its argument, 
right?  Might as well call it after the swap, just to be sure.

Nathan Myers
ncm-nospam@cantrip.org



More information about the Libstdc++ mailing list