Does priority_queue provide a predictable order?

61 Views Asked by At

Does std::priorirty_queue guarantee a specific ordering (regardless of the standard library implementation) when extracting elements in a largest-first order?

Suppose that the comparison function that is provided cannot resolve all ties. For example, we may be storing pairs of integers in the priority queue, and comparing them based on the first value. This way (1,2) and (1,3) compare equal. For a given insertion order with .push(), is a specific extraction order guaranteed when using .pop()? Or is it possible (i.e. consistent with the standard) that some implementations return (1,2) before (1,3) while others return (1,3) first?

0

There are 0 best solutions below