bug in string_algo

Hi Pavol, Downloaded the latest string_algo from the CVS. It seems to be buggy. First of all, I expect the following to work: std::string result; boost::replace_range( result, "\r\n", "\n"); It fails, with a couple of errors (I'm using VC7.1). Since the above failed, tried to create a function to be equivalent: void replace( std::string & str, const char * find, const char * replace) { boost::replace_range( str, boost::make_range(find, find + strlen(find)), boost::make_range(replace, replace + strlen(replace)) ); } This also fails to compile: d:\boost\boost_latest_sandbox\boost-sandbox\boost\string_algo\iterator_range.hpp(96) : error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::iterator::iterator(std::basic_string<_Elem,_Traits,_Ax>::iterator::pointer)' : cannot convert parameter 1 from 'const char *' to 'std::basic_string<_Elem,_Traits,_Ax>::iterator::pointer' with [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char> ] and [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char> ] Conversion loses qualifiers d:\john\projects\logview\log_handler.cpp(6) : see reference to function template instantiation 'boost::iterator_range<IteratorT>::iterator_range<const char*>(const boost::iterator_range<const char *> &)' being compiled with [ IteratorT=boost::string_algo::container_traits<std::string>::iterator ] d:\boost\boost_latest_sandbox\boost-sandbox\boost\string_algo\iterator_range.hpp(96) : error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::iterator::iterator(std::basic_string<_Elem,_Traits,_Ax>::iterator::pointer)' : cannot convert parameter 1 from 'const char *' to 'std::basic_string<_Elem,_Traits,_Ax>::iterator::pointer' with [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char> ] and [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char> ] Conversion loses qualifiers This seems pretty unacceptable to me. Best, John

Hi John, I'm not sure what are you trying to do, but it seems, that you are using a wrong function. If you want replace all occurences of "\r\n" with "\n", then you need to use replace_all function. replace_range is intended to replace a specific range in a sequence with something else. This range *must* point into the input sequece, otherwise the result is undefined. Usualy you will use this function to alter a part of sequence, that has been identified by some find algorithm. As for the sandbox, version there is quite outdated. Actualy I haven't touch it since the formal review. Currently, I'm applying the change requested during the review. Hopefuly in a week or two I will be able to upload a first version to main CVS tree. Regards, Pavol On Wed, Mar 03, 2004 at 03:41:43PM +0200, John Torjo wrote:
Hi Pavol,
Downloaded the latest string_algo from the CVS. It seems to be buggy.
First of all, I expect the following to work: std::string result; boost::replace_range( result, "\r\n", "\n");
It fails, with a couple of errors (I'm using VC7.1).
Since the above failed, tried to create a function to be equivalent:
void replace( std::string & str, const char * find, const char * replace) { boost::replace_range( str, boost::make_range(find, find + strlen(find)), boost::make_range(replace, replace + strlen(replace)) ); }
This also fails to compile: d:\boost\boost_latest_sandbox\boost-sandbox\boost\string_algo\iterator_range.hpp(96) : error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::iterator::iterator(std::basic_string<_Elem,_Traits,_Ax>::iterator::pointer)' : cannot convert parameter 1 from 'const char *' to 'std::basic_string<_Elem,_Traits,_Ax>::iterator::pointer' with [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char> ] and [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char> ] Conversion loses qualifiers d:\john\projects\logview\log_handler.cpp(6) : see reference to function template instantiation 'boost::iterator_range<IteratorT>::iterator_range<const char*>(const boost::iterator_range<const char *> &)' being compiled with [
IteratorT=boost::string_algo::container_traits<std::string>::iterator ] d:\boost\boost_latest_sandbox\boost-sandbox\boost\string_algo\iterator_range.hpp(96) : error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::iterator::iterator(std::basic_string<_Elem,_Traits,_Ax>::iterator::pointer)' : cannot convert parameter 1 from 'const char *' to 'std::basic_string<_Elem,_Traits,_Ax>::iterator::pointer' with [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char> ] and [ _Elem=char, _Traits=std::char_traits<char>, _Ax=std::allocator<char> ] Conversion loses qualifiers
This seems pretty unacceptable to me.
Best, John
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
John Torjo
-
Pavol Droba