title: Using std::unique and vector.erase to remove all but last occurrence of duplicate elements
body: <p>How can I efficiently remove all the duplicates of a stable sorted vector while keeping the last element in order instead of the first?</p>
  
  <p>It's fairly straightforward to keep the first one by doing:</p>
  
  <pre><code>auto it = std::unique( vector.begin(), vector.end() ,[](string a, string b){ return ! (a.compare(b));});
  vector.erase(it,vector.end());
  </code></pre>
  
  <p>But I am not sure how to do the same while keeping the last duplicate element.
  It can probably be done with reverse iterators,starting the unique search process from the end of the vector but I having trouble combining it with the use of the erase function.</p>
  
  <p>EDIT:
  I found the solution by modifying the sorting method. Keeping the first duplicate now suffices.</p>