Boost logo

Boost :

Subject: Re: [boost] [range] Extended... maybe?
From: Neil Groves (neil_at_[hidden])
Date: 2009-04-16 16:05:05


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_at_[hidden]> wrote:
> 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
>
>

-- 
Sent from my mobile device

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