title: "Locking" two vectors and sorting them
body: <p>I have this two <code>vector&lt;double&gt;</code> 's <code>mass</code> and <code>velocity</code> both of the same size <code>N</code>. They contain the information about the mass and velocity of N particles. <code>mass[i]</code> and <code>velocity[i]</code> are thus properties of the i'th particle </p>
  
  <p>Is it possible in C++ to "lock" these two vectors together and sort them in increasing order of mass? 
  Thus after the sorting the vector <code>mass</code> should be in increasing order, and the velocity vector should contain the corresponding velocities of the sorted masses</p>
  
  <p>e.g. Before sorting mass = (4,2,1,3) and velocity = (13, 14,15,16 )
       After sorting mass=(1,2,3,4) and velocity =(15, 14, 16, 13)</p>
  
  <p>The one (non-efficient) way I know for this is to transfer the data into an vector of struct's</p>
  
  <pre><code>struct particle
  {
  
  double mass;
  double velocity;
  
  
  bool operator &lt; (const particle&amp; str) const
  
   {
      return (mass &lt; str.mass);
    }
  
  
  
  };
  </code></pre>
  
  <p>and create <code>vector&lt;particle&gt; particlelist(N)</code> and then sort this vector by using the <code>std::sort</code> by overloading the <code>&lt;</code> operator as I have done in the definition above. </p>
  
  <p>I do not want to put my data into Array of Structures fashion since I have heard it is inefficient compared to the Structure of Arrays approach(at least in CUDA). </p>