Consider a std::priority_queue where N elements have the same priority. Now consider some pop()s and push()s of elements with any priority, so that the resulting queue consists of all those N elements mentioned above plus M new elements, where all the N+M elements have the same priority.
Does a following pop() guarantee that the removal of the top element follows a FIFO order in which the first inserted element is removed first?
Another question is how can I find an element and remove it from a priority queue? (a short examples is appreciated)
I don’t think there is any such guarantee. According to to sgi’s docs, it depends on the underlying data structure.
I think most common implementations use a heap. Pushing and popping any item on a heap simply updates the elements in it in such a way that there is no node where its children are larger than the parent (for max heap). In the case where both children have the same priority and one of them must take the place of the parent, there is no distinction made on choosing which node to promote. So it is entirely up to the implementation to pick the left or the right node.
If you really need to have the nodes in FIFO order if all priorities are equal, pass in a comparison function that first orders by priority and breaks ties by using a value stored in the object that holds the number of objects pushed into the priority_queue before it.