title: How to remove duplicates from unsorted std::vector while keeping the original ordering using algorithms?
body: <p>I have an array of integers that I need to remove duplicates from while maintaining the order of the first occurrence of each integer. I can see doing it like this, but imagine there is a better way that makes use of STL algorithms better? The insertion is out of my control, so I cannot check for duplicates before inserting.</p>
  
  <pre><code>int unsortedRemoveDuplicates(std::vector&lt;int&gt; &amp;numbers) {
      std::set&lt;int&gt; uniqueNumbers;
      std::vector&lt;int&gt;::iterator allItr = numbers.begin();
      std::vector&lt;int&gt;::iterator unique = allItr;
      std::vector&lt;int&gt;::iterator endItr = numbers.end();
  
      for (; allItr != endItr; ++allItr) {
          const bool isUnique = uniqueNumbers.insert(*allItr).second;
  
          if (isUnique) {
              *unique = *allItr;
              ++unique;
          }
      }
  
      const int duplicates = endItr - unique;
  
      numbers.erase(unique, endItr);
      return duplicates;
  }
  </code></pre>
  
  <p>How can this be done using STL algorithms?</p>