Boost logo

Boost Users :

Subject: Re: [Boost-users] boost solution for transforming stl algorithms on proxy iterators?
From: Oswin Krause (Oswin.Krause_at_[hidden])
Date: 2012-10-17 02:08:56


I have thought a bit about this issue.

would there be a general interest in a boost.iterator conforming
implementation of stl algorithms?

On 2012-10-16 14:40, Jeffrey Lee Hellrung, Jr. wrote:
> On Tue, Oct 16, 2012 at 3:25 AM, Oswin Krause
> <Oswin.Krause_at_[hidden] [1]> wrote:
>
>> Hi,
>>
>> I often have problems which look a bit like this:
>>
>>     //example code, only for problem statement
>>     //std::vector<bool> chosen only because it is no container
>> :). If this is too silly for you,
>>     //think about a matrix interpreted as range of row-vectors.
>>     std::vector<bool> myContainer;//does only have proxy
>> iterators.
>>     std::vector<double> myDistances; //stores for every element
>> in myContainer a distance
>>
>>     //now i want to to sort the elements of both ranges in place
>>     //as if they were in a hypothetic range
>> std::vector<std::pair<bool, double> >
>>     //and sort them by the second part:
>>    
>> boost::sort(make_key_value_range(myContainer,myDistances));//bam,
>> not allowed
>>
>> I omited the definition of make_key_value_range but it should be
>> clear that this returns a proxy range with writable iterators and
>> reference type similar to
>> std::pair<std::vector<bool>::reference,double&> for which swap is
>> overloaded to do the right thing.
>
> You should be able to equally well use zip_iterator's, or, if
> supported by Boost.Range, something like a make_zip_range.
>  
>
>> This is not allowed by the standard as boost::sort calls std::sort
>> which in turn requires random_access_iterators - and they disallow
>> proxy references.
>
> Ugh, yes :(
>
>
>
> Links:
> ------
> [1] mailto:Oswin.Krause_at_[hidden]
> [2] http://en.wikipedia.org/wiki/Introsort


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net