Set with custom compare In my project I use std::set with custom Compare function for maintaining an event queue. It fulfills following criteria:


event duplication is not allowed
should maintain the insertion order


(tried std::vector first, but that performed poorly because of complicated duplicate removal)

The important code is:


template &lt;typename T&gt;
class EventQueue {
public:
  EventQueue() : set_(std::set&lt;DataWrap&gt;()) {}
  void Insert(T elem) {
    set_.insert(DataWrap(elem, set_.size()));
  }

  // ....

private:
  struct DataWrap {
    T data;
    unsigned int order;
    DataWrap(T d, unsigned int o) : data(d), order(o) {}
    bool operator&lt;(const DataWrap&amp; other) const {
      if (data == other.data)
        return false;
      else
        return order &lt; other.order;
    }
  };
  std::set&lt;DataWrap&gt; set_;
};


Naturally I want to avoid undefined behaviour. As far as I can see my Compare fulfills the requirements of strick weak ordering (irreflexive, transitive, asymetric)

Can you confirm that this code is well-defined, or am I missing something? Thanks for your time!
As a side note, you pass the element by copy not by const reference. This might also have some real preformance effects. SO rather do

 void Insert(const T&amp;) 


Also you could use emplace_back to enable inplace construction of the elements in the vector. On the other hand std::find only takes const T&amp; so I would guess, that move semantics do not really buy you anything here.