title: std::unique and removing duplicates from a container of objects
body: <p>I would like to know if there is an efficient way to remove objects from a container based on values of member fields of the objects.  For example, I can do the following using stl::unique with a list of strings:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include&lt;iostream&gt;
  #include&lt;list&gt;
  #include&lt;string&gt;
  #include&lt;algorithm&gt;
  using namespace std;
  
  bool stringCompare(const string &amp; l, const string &amp; r)                                                                                   
  {                                                                                                                                    
     return (l==r);                                                                                                                         
  }
  
  int main()                                                                                                                               
  {                                                                                                                                        
  
    list&lt;string&gt; myStrings;                                                                                                                
    myStrings.push_back("1001");                                                                                                           
    myStrings.push_back("1001");                                                                                                           
    myStrings.push_back("81");                                                                                                             
    myStrings.push_back("1001");                                                                                                           
    myStrings.push_back("81");                                                                                                             
  
    myStrings.sort();                                                                                                                      
    myStrings.erase(unique(myStrings.begin(), myStrings.end(), stringCompare), myStrings.end());                                           
  
    list&lt;string&gt;::iterator it;                                                                                                             
    for(it = myStrings.begin(); it != myStrings.end(); ++it)                                                                               
    {                                                                                                                                      
      cout &lt;&lt; *it &lt;&lt; endl;                                                                                                                 
    }                                                                                                                                      
  
    return     0;                                                                                                                              
  }
  </code></pre>
  
  <p>prints 1001, 81...</p>
  
  <p>Is there a way I can do something similar with the following code, or do I need to perform the comparisons "manually" using operators and iterating through the containers. I couldn't think of a more elegant solution and would like to know if this is possible without writing a lot of code. Any help will be much appreciated! </p>
  
  <pre class="lang-cpp prettyprint-override"><code>class Packet
  {
  public:
  Packet(string fTime, string rID) : filingTime(fTime), recordID(rID)
  
    string getFilingTime() {return filingTime;}
    string getRecordId() {return recordID;}
  
  private:
    string filingTime;
    string recordID;
  
  };
  
  int main()
  {
  vector&lt;Packet*&gt; pkts;
  pkts.push_back(new Packet("10:20", "1004"));
  pkts.push_back(new Packet("10:20", "1004")); // not unique (duplicate of the line above)
  pkts.push_back(new Packet("10:20", "251"));
  pkts.push_back(new Packet("10:20", "1006"));
  
  // remove packet from vector if time and ID are the same
  
  return 0;
  }
  </code></pre>
  
  <p>Thanks</p>