On Jun 10, 12:01 pm, rpbg...@yahoo.com (Roland Pibinger) wrote:
On Sat, 09 Jun 2007 19:51:47 -0000, James Kanze wrote:
Thus, I
can use std::replace (from <algorithm>) on a string, but also on
a vector, a deque or a list.
OTOH, what basic_string::replace() does (or the desired replace_all())
cannot be done with std::replace().
Yes. There are a very few fundamental operations on string
which are just for string. Replace and its derivatives (insert,
append, erase) are examples. But note that despite having the
same name, std::replace and std::basic_string::replace have two
very different semantics: std::replace (or std::replace_if)
replaces according to the value; std::basic_string::replace
replaces according to position.
In other containers, you don't have replace, but you do have
insert and erase; operations which modify the topology of the
container are generally members.
The original question concerned something somewhat more complex,
since it involved a replace operation changing topology, but
dependent on value, and not position. As such, it certainly
doesn't fit as a member (because of value), and can't be done
with the classical algorithms, because they generally don't
support changing topology. Thus, a totally new component,
regex.
--
James Kanze (Gabi Software) email:
ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34