<div class="gmail_quote">On Tue, Oct 16, 2012 at 3:25 AM, Oswin Krause <span dir="ltr">&lt;<a href="mailto:Oswin.Krause@ruhr-uni-bochum.de" target="_blank">Oswin.Krause@ruhr-uni-bochum.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I often have problems which look a bit like this:<br>
<br>
    //example code, only for problem statement<br>
    //std::vector&lt;bool&gt; chosen only because it is no container :). If this is too silly for you,<br>
    //think about a matrix interpreted as range of row-vectors.<br>
    std::vector&lt;bool&gt; myContainer;//does only have proxy iterators.<br>
    std::vector&lt;double&gt; myDistances; //stores for every element in myContainer a distance<br>
<br>
    //now i want to to sort the elements of both ranges in place<br>
    //as if they were in a hypothetic range std::vector&lt;std::pair&lt;bool, double&gt; &gt;<br>
    //and sort them by the second part:<br>
    boost::sort(make_key_value_<u></u>range(myContainer,myDistances)<u></u>);//bam, not allowed<br>
<br>
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&lt;std::vector&lt;bool&gt;::<u></u>reference,double&amp;&gt; for which swap is overloaded to do the right thing.<br>
</blockquote><div><br>You should be able to equally well use zip_iterator&#39;s, or, if supported by Boost.Range, something like a make_zip_range.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


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.</blockquote><div><br>Ugh, yes :(<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 This issue is AFAIK resolved with C++11 but some of us still need to support C++03 - and I am really annoyed by this problem.<br></blockquote><div><br>Hmmm...how is this resolved in C++11? AFAIK, C++11 still uses the old archaic iterator categories and requires a real C++ reference as the reference type of forward iterators.<br>
<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The thing is: this will compile on most compilers. One could just lie about the iterator category, saying it is a random_access_iterator and even VC would be happy with it. However it could just break randomly on a new compiler without warning or has severe performance issus (for example gcc works, but completely ignores my nicely defined swap and instead does a triangle copy :-( ).<br>

<br>
So how can one resolve this issue? I have the problem, that i need to do this in-place, since copying would result in std::bad_alloc almost surely. Also the above single line of code just looks that nice, that i just want to have it this way.<br>

<br>
So, how do you resolve this issue? is there maybe some boost library capable of getting this done? e.g. boost.betterSTL? :-).<br></blockquote><div><br>I agree, this is a deficiency in the standard. Unfortunately, maybe the only thing you can do to guarantee this works in a portable way is to code up your own introsort [1] implementation :/<br>
<br>- Jeff<br><br>[1] <a href="http://en.wikipedia.org/wiki/Introsort">http://en.wikipedia.org/wiki/Introsort</a><br><br></div></div>

