Performance, mainly. An std::deque
has all of the
functionality of std::vector
, at least for normal use, but
indexing and iterating over it will typically be somewhat
slower; the same may hold for appending at the end, if you've
used reserve
. And of course, std::vector
is the default
container, using anything else will suggest to the reader that
you have special requirements.
std::vector
also guarantees contiguity, so it (and only it)
can be used to interface legacy functions which require a T*
or a T const*
.
I might add that the one time I actually had a performance
issue, and measured, std::vector
was faster than std::deque
,
despite the fact that I was regularly removing elements from
the front (using the container as a queue, pushing at the back,
and popping at the front). I don't know if that generalizes,
however; in my case, the queue was relatively short (never more
than about 15 elements, and usually many less), and the contents
were char
, which is extremely cheap to copy. But in general,
I'd use std::vector
even if I needed to remove elements from
the front, if only because of its better locality. I'd probably
only consider std::deque
if I expected thousands of elements,
which were expensive to copy.