The Standard Library: Overview

Steven J. Zeil

Last modified: Oct 26, 2023
Contents:

 
A large project builds upon libraries of ADTs built for that specific project, or that have been collected by the company for related projects (a.k.a. domain-specific ADTs). These in turn are generally built upon the library of ADTs provided by all C++ compilers. This standard C++ library is called “std”.

1 std/STL Containers

The key components of std are

You are already familiar with many parts of std. You presumably were already familiar with the I/O portion. We have already looked at some utilities. Now we want to do a quick overview of the containers portion, prior to beginning to look at some of the specific containers in detail.

You may or may not have heard of the “STL” library before. When the C++ standards committee was considering what should be included in the standard library, std, the early drafts included what we now recognize as the I/O and utility sections. A group of researchers from HP then proposed addition of their STL library to std. STL consisted of a set of containers, iterators, and function templates (algorithms). “STL” stands for “Standard Template Library”, which may have been a bit presumptuous because it certainly was not part of the standard at the time. The C++ standards committee eventually accepted the STL, with some revisions, as part of std.

2 The std Containers

We call an ADT a “container” if its main purpose is to provide a collection of items of some other, simpler type.

2.1 Sequential and Associative

Collections come in two flavors

sequential
values are accessed in an order determined by their insertion.

The std sequential containers are array, initializer_list, vector, deque, list, stack, queue, and priority queue.

associative
allow “random” access

The std associative containers are set, map, multiset, multimap, unordered_set, unordered_map, unordered multiset, and unordered_multimap.

The first four “ordered” containers are based on trees. The four “unordered” containers are based on hashing.

We’ll look at all of these in upcoming lessons.

2.2 Consistent Interfaces

One goal of the std library is to provide consistent interfaces to many different containers.

Examples:

2.3 A Matter of Style

Because of this consistency in the interfaces, learning to use the std containers is more a matter of learning the std “style” than of learning 10-14 different ADT interfaces.

You can find a handy summary of the container interfaces in my STL containers reference sheets. You can also find some very good overviews and documentation from cplusplus.com.