title: Reorder vector using a vector of indices
body: <p>I'd like to reorder the items in a vector, using another vector to specify the order:</p>
  
  <pre><code>char   A[]     = { 'a', 'b', 'c' };
  size_t ORDER[] = { 1, 0, 2 };
  
  vector&lt;char>   vA(A, A + sizeof(A) / sizeof(*A));
  vector&lt;size_t> vOrder(ORDER, ORDER + sizeof(ORDER) / sizeof(*ORDER));
  <BR>reorder_naive(vA, vOrder);
  <BR>// A is now { 'b', 'a', 'c' }
  </code></pre>
  
  <p>The following is an inefficient implementation that requires copying the vector:  </p>
  
  <pre><code>void reorder_naive(vector&lt;char>& vA, const vector&lt;size_t>& vOrder)  
  {   
      assert(vA.size() == vOrder.size());  
      vector vCopy = vA; // Can we avoid this?  
      for(int i = 0; i &lt; vOrder.size(); ++i)  
          vA[i] = vCopy[ vOrder[i] ];  
  }  
  </code></pre>
  
  <p>Is there a more efficient way, for example, that uses swap()?</p>