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@ruhr-uni-bochum.de [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@ruhr-uni-bochum.de [2] http://en.wikipedia.org/wiki/Introsort