The C ++ STL priority queue has the void pop () method and the const ref top () method. Thus, if you want to move items from the queue, you should do something like this:
T moved = std::move(const_cast<T&>(myQueue.top()))); myQeue.pop();
This effectively translates the vertex not into a constant, so it can be moved (rather than copied). I donβt like this code, because a forced move can invalidate the priority queue invariants, which should not matter due to pop music, but everything can go wrong.
Is there a better way to execute a pop / move? Why is there no T&& top_and_pop () function?
c ++ c ++ 11 move-semantics c ++ 03
Ant6n
source share