Taken from here http://www.cplusplus.com/reference/queue/priority_queue/
Compare
A binary predicate that takes two elements (of type T) as arguments and returns a bool.
The expression comp(a,b), where comp is an object of this type and a and b are elements in the container, shall return true if a is considered to go before b in the strict weak ordering the function defines.
When writing a compare function is there any way of telling which element has been waiting in the queue longer?
Assuming the compare function is called whenever a new element is to be inserted, will 'a' always be the new item and 'b' be an element already in the queue? Or does it work differently?
My idea was that something like this:
bool my_class::operator()(const my_class &a, const my_class &b) {
//Lower priority comes first
return (a.get_priority() < b.get_priority());
}
When the priority of 'a' and 'b' are the same then 'b' is given priority because it has been in the queue longer.
Thankyou for any feedback on how std::queue works and how I might achieve my goal.