Clearing std::queue
I stumbled upon a line of code during the review. One of my colleagues wanted to cleat the std::queue and he did:
std::queue<int> empty; std::swap(my_queue, empty);
I asked him why he didn’t use my_queue.clear() and realized that std::queue doesn’t implement it. Looks like there are couple of ways to do it and I think the best one I found is the one that will work only in c++11:
my_queue = {};
Simple and clear. Swap is a bit ambiguous because doesn’t show the clear intention what we are trying to achieve. Assignment to the empty initializer list is clear enough.




















