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: [PATCH] Basic_string::_M_replace clean up


On Sun, Dec 09, 2001 at 02:07:11AM +0100, Paolo Carlini wrote:
> So we should find a way to enable _M_replace(forward_iterator) to 
> distinguish those cases when it is in fact called from 
> _M_replace(input_iterator) which has already buffered in an independent 
> string.  What do you suggest? In fact detecting those situations 
> (independent strings) would help not buffering at all inside 
> _M_replace(forward_iterator) also in the other uses of it. I would be
> happy to work on this. Which (fast!) options are available to detect 
> when to pairs of iterators do not overlap?

Add another version of replace so you have replace_safe and 
replace_paranoid.  (Of course you only have to rename one.)  Maybe
the second can call the first after making its copy, and anybody else 
can call the first if they know what they're doing.

You can also overload for the cases of actual pointer arguments or actual 
string iterators, and then compare the pointers to the string contents to 
discover overlap.  (This would involve inline forwarding functions to 
dispatch to the right places.)

Replacing the empty sequence at the beginning, or end, of a string 
is likely to be a common case, too, and each is safe against overlap.

Thank you for your generosity with your time.

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]