title: how do you insert the value in a sorted vector?
body: <p>ALL,</p>
  
  <p>This question is a continuation of <a href="https://stackoverflow.com/questions/15582504/is-there-a-sorted-container-in-stl">this one</a>.
  I think that STL misses this functionality, but it just my IMHO.</p>
  
  <p>Now, to the question.</p>
  
  <p>Consider following code:</p>
  
  <pre><code>class Foo
  {
  public:
      Foo();
      int paramA, paramB;
      std::string name;
  };
  
  struct Sorter
  {
      bool operator()(const Foo &amp;foo1, const Foo &amp;foo2) const
      {
           switch( paramSorter )
           {
               case 1:
                   return foo1.paramA &lt; foo2.paramA;
               case 2:
                   return foo1.paramB &lt; foo2.paramB;
               default:
                   return foo1.name &lt; foo2.name;
           }
      }
  
      int paramSorter;
  };
  
  int main()
  {
      std::vector&lt;Foo&gt; foo;
      Sorter sorter;
      sorter.paramSorter = 0;
          // fill the vector
      std::sort( foo.begin(), foo.end(), sorter );
  }
  </code></pre>
  
  <p>At any given moment of time the vector can be re-sorted.
  The class also have the getter methods which are used in the sorter structure.</p>
  
  <p>What would be the most efficient way to insert a new element in the vector?</p>
  
  <p>Situation I have is:</p>
  
  <p>I have a grid (spreadsheet), that uses the sorted vector of a class. At any given time the vector can be re-sorted and the grid will display the sorted data accordingly.</p>
  
  <p>Now I will need to insert a new element in the vector/grid.
  I can insert, then re-sort and then re-display the whole grid, but this is very inefficient especially for the big grid.</p>
  
  <p>Any help would be appreciated.</p>