title: C++ sorting and keeping track of indexes
body: <p>Using C++, and hopefully the standard library, I want to sort a sequence of samples in ascending order, but I also want to remember the original indexes of the new samples.</p>
  <p>For example, I have a set, or vector, or matrix of samples <code>A : [5, 2, 1, 4, 3]</code>. I want to sort these to be  <code>B : [1,2,3,4,5]</code>, but I also want to remember the original indexes of the values, so I can get another set which would be:
  <code>C : [2, 1, 4, 3, 0 ]</code> - which corresponds to the index of each element in 'B', in the original 'A'.</p>
  <p>For example, in Matlab you can do:</p>
  <pre><code> [a,b]=sort([5, 8, 7])
   a = 5 7 8
   b = 1 3 2
  </code></pre>
  <p>Can anyone see a good way to do this?</p>