Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#5714 closed Bugs (invalid)

replace_all does not allow to replace single chars

Reported by: anonymous Owned by: Pavol Droba
Milestone: To Be Determined Component: string_algo
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc:

Description

Following code does not compile:

#include <string>
#include <boost/algorithm/string.hpp>

using namespace std;
using namespace boost;
using namespace boost::algorithm;

int main()
{
    string str = "abc";
    replace_all(str, 'a', 'A');
}
/usr/include/boost/algorithm/string/replace.hpp: In function 'void boost::algori
thm::replace_all(SequenceT&, const Range1T&, const Range2T&) [with SequenceT = s
td::string, Range1T = char, Range2T = char]':
x.cc:11:   instantiated from here
/usr/include/boost/algorithm/string/replace.hpp:654: error: no matching function
 for call to 'first_finder(const char&)'
/usr/include/boost/algorithm/string/replace.hpp:654: error: no matching function
 for call to 'const_formatter(const char&)'

Change History (2)

comment:1 by Pavol Droba, 11 years ago

Resolution: invalid
Status: newclosed

'a' is not string-type supported by boost::range, therefore it is not a valid argument to function replace_all. Use "a" insteda.

comment:2 by anonymous, 11 years ago

I agree that boost::range modification just to support this case may be undesirable. On the other hand it will be good to provide specialized version of replace_all() and other functions in this library, which are optimized for single characters. Please consider adding them.

Note: See TracTickets for help on using tickets.