Sequence containers

The sequence containers keep the elements in the order you specify when adding the elements to the container. The sequence containers are std::array, std::vector, std::deque, std::basic_string, std::list, and std::forward_list. Things you need to know before choosing a sequence container are as follows:

  1. Number of elements (order of magnitude).
  2. Usage patterns: How often are you going to add data? Read/traverse data? Delete data? Rearrange data?
  3. Do you need to sort the elements?

When adding elements to a sequence container, you always specify where in the sequence the should be located. For example, when adding an element to a vector you can call push_back, which will add the new element last in the container.

Get C++ High Performance 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.