Why does std::stack use std::deque by default?

As the container grows, a reallocation for a vector requires copying all the elements into the new block of memory. Growing a deque allocates a new block and links it to the list of blocks - no copies are required.

Of course you can specify that a different backing container be used if you like. So if you have a stack that you know is not going to grow much, tell it to use a vector instead of a deque if that's your preference.


See Herb Sutter's Guru of the Week 54 for the relative merits of vector and deque where either would do.

I imagine the inconsistency between priority_queue and queue is simply that different people implemented them.