11 STL here – The C++ Standard Template Library

 

This chapter covers

  • Exploring the C++ Standard Template Library (STL)
  • Understanding how to work with STL containers
  • Practicing the use of iterators and understanding their importance
  • Practicing some useful STL algorithms
  • Exploring the concept of functors (function objects)

In this chapter, we explore one of the most powerful libraries C++ has to offer: The Standard Template Library, also known as the STL. The STL is a comprehensive library with an incredible collection of reusable ready-to-use, high-quality implementations of data structures and algorithms. However, the STL is a huge subject that can cover a whole book, and in this Chapter (and book) we cannot cover it in its entirety.

We start this Chapter by exploring the various containers the STL has to offer, and explain how each container is designed to store and organize data. You will then learn all about iterators - an essential tool for traversing and manipulating elements within containers. You will learn about different iterator types, and their role, and practice some code.

We then move on and explore the fascinating world of STL algorithms. You will learn and practice how to perform a wide range of operations powered by algorithms, such as searching, sorting, shuffling, accumulating values, and more.

11.1 The STL – The stick that holds the C++ candy

11.1.1 The STL candy store: algorithm, containers, functions, and iterators

11.2 Containers – Your ultimate object holder

11.2.1 In sequence: C++ sequence containers

11.2.2 Join the association of associative containers

11.2.3 Derive me crazy – Derived containers (container adaptors)

11.3 Iterators: A bridge between algorithms and containers

11.3.1 Just do ‘it’ - A closer look into the STL iterators

11.4 Algorithms: The artistry of awesomeness

11.4.1 The anatomy the STL algorithms

11.4.2 Non-modifying algorithms

11.4.3 Sorting algorithms

11.4.4 Numeric algorithms

11.4.5 Removal algorithms

11.4.6 Mutating algorithms

11.5 The X-Functor: A mini introduction to functors

11.5.1 Using Functors

11.6 Summary