Chapter Overview
Get an idea of what we'll learn in this chapter.
We'll cover the following...
In this chapter, we will focus on the container classes in the STL. In short, a container is an object that contains a collection of other objects, or elements. The STL provides a complete suite of container types that form the foundation of the STL itself.
A quick overview of the STL container types
The STL provides a comprehensive set of container types, including sequential containers, associative containers, and container adapters. Here's a brief overview:
Sequential containers
The sequential containers provide an interface where the elements are arranged in sequence. While we may use the elements sequentially, some of these containers use contiguous storage, and others do not. The STL includes these sequential containers:
The
array
is a fixed-size sequence that holds a specific number of elements in contiguous storage. Once allocated, it cannot change size. This is the simplest and fastest contiguous storage container.The
vector
is like an array that can shrink and grow. Its elements are stored contiguously, so changing size may involve the expense of allocating memory and moving data. Avector
may keep extra space in reserve to mitigate that cost. Inserting and deleting elements from anywhere other than the back of avector
will trigger realignment of the elements to ...