Boost logo

Boost :

Subject: [boost] [range] Extended... maybe?
From: Vladimir.Batov_at_[hidden]
Date: 2009-04-16 00:01:19


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");


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk