
I am trying something looking fairly reasonable: string str1 = boost::replace_all_copy(str, 'x', '0'); It obviously fails to compile with: error: no matching function for call to 'begin(const char&)' error: no matching function for call to 'end(const char&)' as replace_all_copy() wants boost::ranges for the 2nd and 3rd parameters: replace_all_copy( const SequenceT &, const Range1T &, const Range2T &); and 'x' and '0' are not boost::ranges. Would that be sensible to extend boost::range along the following lines to allow string_algo to work with individual characters? namespace boost { template<> struct range_iterator<char> { typedef char* type; }; template<> struct range_const_iterator<char> { typedef char const* type; }; namespace range_detail { template<> inline char const* boost_range_begin(char const& c) { return &c; } template<> inline char const* boost_range_end(char const& c) { return &c + 1; } } } Thanks, Vladimir. P.S. I do understand that the following works string str1 = boost::replace_all_copy(str, "x", "0");

Vladimir.Batov@wrsa.com.au skrev:
I am trying something looking fairly reasonable:
string str1 = boost::replace_all_copy(str, 'x', '0');
It obviously fails to compile with:
error: no matching function for call to 'begin(const char&)' error: no matching function for call to 'end(const char&)'
as replace_all_copy() wants boost::ranges for the 2nd and 3rd parameters:
replace_all_copy( const SequenceT &, const Range1T &, const Range2T &);
and 'x' and '0' are not boost::ranges. Would that be sensible to extend boost::range along the following lines to allow string_algo to work with individual characters?
namespace boost { template<> struct range_iterator<char> { typedef char* type; }; template<> struct range_const_iterator<char> { typedef char const* type; }; namespace range_detail { template<> inline char const* boost_range_begin(char const& c) { return &c; } template<> inline char const* boost_range_end(char const& c) { return &c + 1; } } }
I think single_element_range(x) has been proposed several times. Maybe Neil could include it in range_ex? -Thorsten

I shall implement a single element range in the next batch of updates. The proposed char pointer code has a subtle flaw since the +1 on the char pointer is not guaranteed to be valid. For example, if the char was at the uppermost address. My intended solution is to use a new iterator class. element_as_range seems like a descriptive name, but perhaps someone has a better shorter suggestion. On 4/16/09, Thorsten Ottosen <thorsten.ottosen@dezide.com> wrote:
Vladimir.Batov@wrsa.com.au skrev:
I am trying something looking fairly reasonable:
string str1 = boost::replace_all_copy(str, 'x', '0');
It obviously fails to compile with:
error: no matching function for call to 'begin(const char&)' error: no matching function for call to 'end(const char&)'
as replace_all_copy() wants boost::ranges for the 2nd and 3rd parameters:
replace_all_copy( const SequenceT &, const Range1T &, const Range2T &);
and 'x' and '0' are not boost::ranges. Would that be sensible to extend boost::range along the following lines to allow string_algo to work with individual characters?
namespace boost { template<> struct range_iterator<char> { typedef char* type; }; template<> struct range_const_iterator<char> { typedef char const* type; }; namespace range_detail { template<> inline char const* boost_range_begin(char const& c) { return &c; } template<> inline char const* boost_range_end(char const& c) { return &c + 1; } } }
I think single_element_range(x) has been proposed several times. Maybe Neil could include it in range_ex?
-Thorsten
-- Sent from my mobile device

Thorsten Ottosen wrote:
Mathias Gaunard skrev:
Thorsten Ottosen wrote:
I think single_element_range(x) has been proposed several times. Maybe Neil could include it in range_ex?
Why not simply use boost::list_of(x)?
not very efficient.
I don't see any reason why it couldn't be as efficient as single_element_range(x). Also, list_of can also be used for to make a range out of n elements.

Mathias Gaunard skrev:
Thorsten Ottosen wrote:
Mathias Gaunard skrev:
Thorsten Ottosen wrote:
I think single_element_range(x) has been proposed several times. Maybe Neil could include it in range_ex?
Why not simply use boost::list_of(x)?
not very efficient.
I don't see any reason why it couldn't be as efficient as single_element_range(x).
Then look at its implementation. boost::assign::ref_list_of<1>(x); is efficient.
Also, list_of can also be used for to make a range out of n elements.
yup. -Thorsten
participants (6)
-
Mathias Gaunard
-
Neil Groves
-
Stjepan Rajko
-
Thorsten Ottosen
-
Vladimir Batov
-
Vladimir.Batov@wrsa.com.au