Boost logo

Boost :

Subject: Re: [boost] [range] Extended... maybe?
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2009-04-16 15:03:15


Vladimir.Batov_at_[hidden] 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


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