Chapter 7. Using vector
and deque
Difficulty: 3
What is the difference between vector
and deque?
When should you use each one? And how can you properly shrink such containers when you no longer need their full capacity? These answers and more, as we consider news updates from the standards front.
In the standard library,
vector
anddeque
provide similar services. Which should you typically use? Why? Under what circumstances would you use the other?What does the following code do?
vector<C> c( 10000 ); c.erase( c.begin()+10, c.end() ); c.reserve( 10 );
A
vector
ordeque
typically reserves extra internal storage as a hedge against future growth, to prevent too-frequent reallocation as new elements are added. Is it possible to completely clear a
Get More Exceptional C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.