What are the trade-offs of using std::deque over std::vector?
Last updated
std::dequeoffers amortized O(1)push_front/push_back, and end insertions don't invalidate references to existing elements (iterators may still be invalidated).It is stored as multiple chunks, not one contiguous block: worse cache locality, slower
operator[], more memory overhead, and nodata()for C APIs.Default to
std::vector. Use deque when you need fast insertion/removal at both ends, such as a queue.