std::deque
std::deque is a double-ended queue. On the surface, it looks like std::vector with better insertions and deletions at both the beginning and the end. While that’s true, remember that this flexibility comes at the cost of a slightly more complex internal structure. If your application requires rapid insertions and deletions at both ends but does not need the tight memory layout of std::vector, std::deque is your container of choice.
Purpose and suitability
std::deque is a container that provides rapid insertions and deletions at both its beginning and end. Its primary strengths are as follows:
- Efficient O(1) insertions and deletions at both ends
- Dynamic size with no need for manual memory management
- Fairly good cache performance for front and back operations
std::deque shines in the following contexts:
- You require random-access capabilities but expect frequent modifications at both ends.
- You need a dynamically sized container...