I have a struct "Telegram" which contains a time offset, the Sender ID, the Receiver ID, and the Message itself:
struct Telegram
{
int Msg; // Message
unsigned long Time; // Time offset (i.e., GetTicks() etc.)
int Sender; // ID of Sender
int Receiver; // ID of Receiver
Telegram(int tMsg, unsigned long tTime, int tSender, int tReceiver):Msg(tMsg), Time(tTime), Sender(tSender), Receiver(tReceiver) {}
// operator override to sort Telegrams by Time.
bool operator<(const Telegram& t1) const
{
return Time < t1.Time;
}
};
I want to store these in an STL set, so that those inserted with low Time offsets appear at the beginning and those with later Time offsets appear towards the back of the set.
So if a duplicate Telegram appears
Example 1:
Telegram(MSG, 50, 1, 2) // MSG, 50 msecs, from ID 1 to ID 2
Telegram(MSG, 50, 1, 2) // MSG, 50 msecs, from ID 1 to ID 2 *IGNORED*
Only one makes it's way into the set.
However... because the set is dependent on the sorting algorithm, the second valid telegram in the next example is lost (all because they have the same Time offset, the STL set assumes they are identical, even though they are going to different people with different messages)
Example 2:
// Same time offset, but between 2 different IDs this time.
Telegram(MSG_CHEESY, 50, 1, 2) // MSG, 50 msecs, from ID 1 to ID 2
Telegram(MSG_CHALKY, 50, 15, 32) // MSG, 50 msecs, from ID 15 to ID 22 *IGNORED - UNFORTUNATELY! :(*
I don't want to use the "multiset", because then I'll get duplicates as seen in Example 1.
Do I need to implement a Pair as a sorting Key here (to allow duplicate Times if the Telegram contents are different)?