priority_queue
doesn't allow iteration through all the members, presumably because it would be too easy in invalidate the priority ordering of the queue (by modifying the elements you traverse) or maybe it's a "not my job" rationale.
The official work-around is to use a vector
instead and manage the priority-ness yourself with make_heap
, push_heap
and pop_heap
. Another work-around, in @Richard's answer, is to use a class derived from priority_queue
and access the underlying storage which has protected
visibility.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…