Deciding Which Sequential Container to Use
Tip
Ordinarily, it is best to use vector
unless there is a good reason to prefer another container.
There are a few rules of thumb that apply to selecting which container to use:
• Unless you have a reason to use another container, use a vector
.
• If your program has lots of small elements and space overhead matters, don’t use list
or forward_list
.
• If the program requires random access to elements, use a vector
or a deque
.
• If the program needs to insert or delete elements in the middle of the container, use a list
or forward_list
.
• If the program needs to insert or delete elements at the front ...
Get C++ Primer, Fifth Edition 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.