I'd rather not rely on swap()
or setting the queue to a newly created queue object, because the queue elements are not properly destroyed. Calling pop()
invokes the destructor for the respective element object. This might not be an issue in <int>
queues but might very well have side effects on queues containing objects.
Therefore a loop with while(!queue.empty()) queue.pop();
seems unfortunately to be the most efficient solution at least for queues containing objects if you want to prevent possible side effects.