Given a std::priority_queue to which elements are being added faster than they are being removed by the usual process of repeatedly popping the best element, so that the program is going to run out of memory unless something is done,
Is there any way to throw away the worst half of the elements, while leaving the best half to be processed one at a time as normal?
There isn’t a direct way. But a binary heap doesn’t really support that operation anyways.
But it’s not hard to indirectly do so: