title: std::sort to sort an array and a list of index?
body: <p>I have a function that takes two vectors of the same size as parameters :</p>
  
  <pre><code>void mysort(std::vector&lt;double&gt;&amp; data, std::vector&lt;unsigned int&gt;&amp; index)
  {
     // For example :
     // The data vector contains : 9.8 1.2 10.5 -4.3
     // The index vector contains : 0 1 2 3
     // The goal is to obtain for the data : -4.3 1.2 9.8 10.5
     // The goal is to obtain for the index : 3 1 0 2
     // Using std::sort and minimizing copies
  }
  </code></pre>
  
  <p>How to solve that problem minimizing the number of required copies ?</p>
  
  <p>An obvious way would be to make a single vector of <code>std::pair&lt;double, unsigned int&gt;</code> and specify the comparator by <code>[](std::pair&lt;double, unsigned int&gt; x, std::pair&lt;double, unsigned int&gt; y){return x.first &lt; y.first;}</code> and then to copy the results in the two original vectors but it would not be efficient.</p>
  
  <p>Note : the signature of the function is fixed, and I cannot pass a single vector of <code>std::pair</code>.</p>