D
Dom Bannon
I have a lot of string-handling code that uses both STL strings and
C-style pointers, for various reasons. It's not really practical to
convert all the code to use iterators instead of pointers.
My problem is that I occasionally have to convert pointers to
iterators to do something useful. To use 'replace', for example, I
have to do something like this:
const char *tkbeg, *tkend; // ptrs in 'linebuf'
....
string::iterator it1 = linebuf.begin() + (tkbeg - linebuf.c_str());
string::iterator it2 = linebuf.begin() + (tkend - linebuf.c_str());
linebuf.replace(it1, it2, getReplacement());
Is there a better way to do this? My concern is that the conversion is
so complex that the compiler is unlikely to recognise it as a no-op,
which is presumably what it is for most compilers.
Thanks -
Dom
C-style pointers, for various reasons. It's not really practical to
convert all the code to use iterators instead of pointers.
My problem is that I occasionally have to convert pointers to
iterators to do something useful. To use 'replace', for example, I
have to do something like this:
const char *tkbeg, *tkend; // ptrs in 'linebuf'
....
string::iterator it1 = linebuf.begin() + (tkbeg - linebuf.c_str());
string::iterator it2 = linebuf.begin() + (tkend - linebuf.c_str());
linebuf.replace(it1, it2, getReplacement());
Is there a better way to do this? My concern is that the conversion is
so complex that the compiler is unlikely to recognise it as a no-op,
which is presumably what it is for most compilers.
Thanks -
Dom