title: C++ Sorting a vector of tuple<string, float> by numerical value, then lexicographically
body: <p>I have a <code>vector&lt;tuple&lt;string, float&gt; &gt;</code> vector that stores the euclidean distance between two nodes, and the node's name. I need to sort this vector by the distance value first, and then by string value. This is so in the instance where two nodes have the same euclidean distance, their sorted position resolves to being done by alphabetical (lexicographical) order of the node names. At the moment, I have a custom sorting helper function that sorts the vector by float value first.</p>
  
  <pre><code>bool sort_second(const tuple&lt;string, float&gt;&amp; a, const tuple&lt;string, float&gt;&amp; b) { 
      return (get&lt;1&gt;(a) &lt; get&lt;1&gt;(b)); 
  } 
  </code></pre>
  
  <p>and call <code>sort(vec.begin(), vec.end(), sort_second)</code> as such. But in the event where nodes <code>foo</code> and <code>bar</code> have the same distance, it's possible for <code>foo</code> to come before <code>bar</code> even though <code>bar</code> should be first. How would I go by sorting the vector a second time (or better yet, on the first pass through) such that I don't mess up the value order that I already computed? Thanks</p>