I experienced unexpected performance behavior of my code which uses a queue. I realized that performance degraded when more elements were in the queue. It turned out that us
queue
is a container adaptor, so you have to understand that the complexity descriptions may refer only to the work the adaptor does itself (which is indeed constant, namely just passing the call through to the underlying container).
For example, see this reference: size()
calls the underlying container's size()
function. For a list
, this has complexity O(n) in C++98/03, and O(1) in C++11.