C++'s STL priority queue have a void pop() method, and a const ref top() method. Thus, if you want to move elements out of the queue, you have to do something like this:
T moved = std::move(const_cast<T&>(myQueue.top())));
myQeue.pop();
This effectively casts the top to not a constant, so that it can be moved (rather than copied). I don't like this code, because the forced move may invalidate the invariants of the priority queue, which should not matter because of the pop, but things could go wrong.
Is there a better way to accomplish the pop/move? Why is there no T&& top_and_pop() function?
top
function returns? Why do that? It will stop any RVO - what are your trying to achieve? – Kop