I have this structure
struct Event {
const string event;
const int order;
Event(const string& _event, const int& _order):event(_event),order(_order) {}
};
struct EventCompare {
bool operator()(const Event& lhs, const Event& rhs)
{
return (lhs.order < rhs.order);
}
};
which I would like to use in a set
:
set<Event, EventCompare> events;
I do know that sets doesn't allow duplicates. However, I would like to define duplicates as two instance of structs
with equal events
regardless of their orders, in other words, A = B
iff A.event == B.event
. This definition has to affect the way the set works, which means that, for example, the set has to ignore Event("holiday", 1)
, if it already contains Event("holiday", 0)
.
How can I do that? I've tried to add
if (lhs.event == rhs.event)
return false;
in my EventCompare
, but that didn't work. Will using pair
instead of struct
help anyhow?