title: How to get the minimum or maximum element in a vector of structures in C++, based on some field in the structure
body: <p>How can I get the minimum or maximum element in a vector of structures in C++, based on some field in the structure?</p>
  <p>For example:</p>
  <pre><code>struct Size {
      int width, height;
  };
  vector&lt;Size&gt; sizes;
  </code></pre>
  <p>And now I want to solve that based on <em>width</em> and create a new vector for that. And then sort based on <em>height</em> and create a new vector for that.</p>