I've read that all stl containers provide a specialisation of the swap algorithm so as to avoid calling the copy constructor and two assignment operations that the default method uses. However, when I thought it would be nice to use a queue in some code I was working on I noticed that (unlike vector and deque) queue doesn't provide this method? I just decided to use a deque instead of a queue, but still I'm interested to know why this is?
C++0x will add swap to container adapters like std::queue. I could only speculate why it is missing from the current standard. In this discussion someone proposes a workaround:
There is a solution since the standard makes the needed parts protected, called inheritance. [just don't destruct via the std adaptors] create a templated struct inheriting the desired adaptor, provide just the constructors and forward the args to the adaptor class, writing a swap member is a snap since the required items are protected members of the standard adaptors.
I'm sure that they were left out as an oversight. In all fairness, I use std::queue and std::stack quite a bit and have never had to swap two. I think your use of a deque instead of a queue is fine. Something like typedef std::deque<MyType> QueueType
should give enough of a hint how the container should be used.
swap is a funding technique which permit the borrower to access one market then exchange the liability for another type of liability