title: Moving object to front of vector c++
body: <p>I have a <code>vector&lt;Suggestions&gt; finalSuggestions</code> that contains a <code>string</code> <code>word</code> and some <code>int</code> <code>num</code>.</p>
  
  <p>If this word meets some condition, I want to move that object to the front of the vector, removing it from wherever it was.</p>
  
  <p>I am able to insert to the beginning of the list with <code>vector::insert</code></p>
  
  <pre><code>for (auto &amp;x: finalSuggestions) {
      if ( double((x.num)/(topword.num)) &lt; 50)
      {
          finalSuggestions.insert(finalSuggestions.begin(),x);
          break;
      }
  }
  </code></pre>
  
  <p>But <strong>I do not know how to remove it from where it is in the list.</strong></p>
  
  <p>For example, for some arbitrary vector <code>{ 1,2,3,4,50,6,7,8,9 }</code>,
  if 50 meets the criteria, move it to the front of the list and delete it from where it was, returning <code>{ 50,1,2,3,4,6,7,8,9 }</code>. The code above returns <code>{ 50,1,2,3,4,50,6,7,8,9 }</code></p>
  
  <p>I was looking into <code>vector::erase</code>, but I'm having problems, and its taking longer than it should.</p>
  
  <p>I envision a simple solution (but this obviously doesn't work)</p>
  
  <pre><code>for (auto &amp;x: finalSuggestions) {
      if ( double((x.num)/(topword.num)) &lt; 50)
      {
          finalSuggestions.insert(finalSuggestions.begin(),x);
          finalSuggestions.erase(x);
          break;
      }
  }
  </code></pre>
  
  <p>I read up on the erase-remove idiom (here is my implementation):</p>
  
  <pre><code> finalSuggestions.erase( remove( begin(finalSuggestions), end(finalSuggestions), x ), end(finalSuggestions) ); 
  </code></pre>
  
  <p>but am getting an error that I don't understand:</p>
  
  <pre><code>In instantiation of '_FIter std::remove(_FIter, _FIter, const _Tp&amp;) [with _FIter = __gnu_cxx::__normal_iterator&lt;Suggestion*, std::vector&lt;Suggestion&gt; &gt;; _Tp = Suggestion]':|
  </code></pre>