Boost logo

Boost Users :

From: John Maddock (john_maddock_at_[hidden])
Date: 2002-07-10 05:48:56


> I have a container (map) with identifiers and value and would like to
> replace variables in a string. The function to perform the replacement I
> wrote needs a const_cast, which makes me a bit nervous. Is this
> necessary? Is there a better way to implement it?

You can't portably use const_cast with string::const_iterator, it works in
this case because the iterator is just a pointer but that is not true on
many platforms (VC7, STLport etc). Better is to use the form of replace
that takes an int position and a length:

s = s.replace( what[2].first - s.begin(), what.length(2), variables[
identifier ] );

John Maddock
http://ourworld.compuserve.com/homepages/john_maddock/index.htm


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net