Home | Projects | Notes > C++ Programming > Sequence Container - std::deque

Sequence Container - std::deque

 

std::deque

 

Initialization and Assignment

Common Methods

For more information, see cppreference.com.

max_size(): Returns the maximum number of elements a vector can theoretically hold on the current

system. This is typically a very large number and depends on system and implementation limits.

L4: Remember, all standard container classes store copies of the elements they hold. So in this case, a copy of p is made.

L6: Creates a temporary (unnamed) person object and adds it to the deque using move semantics.

L8: Constructs the person object directly in place using the constructor. Very efficient - no moves, no copies. It’s built exactly where it needs to be. Use this!

 

Project: Usage of std::deque

std::deque is ideal when you need fast insertions or deletions at both the front and back of the container. It is not optimized for frequent insertions or removals in the middle. If your use case involves modifying elements in the middle, consider using std::list instead.