20. Standard Template Library (STL)

Objectives

In this chapter you'll learn:

  • To be able to use the STL containers, container adapters and "near containers."

  • To be able to program with the dozens of STL algorithms.

  • To understand how algorithms use iterators to access the elements of STL containers.

  • To become familiar with the STL resources available on the Internet and the World Wide Web.

The shapes a bright container can contain!

Theodore Roethke

Journey over all the universe in a map.

Miguel de Cervantes

O! thou hast damnable iteration, and art indeed able to corrupt a saint.

William Shakespeare

That great dust heap called "history."

Augustine Birrell

The historian is a prophet in reverse.

Friedrich von Schlegel

Attempt the end, and never stand to doubt; Nothing's so hard but search will find it out.

Robert Herrick

Outline

20.1 Introduction to the Standard Template Library (STL)
  20.1.1 Introduction to Containers
  20.1.2 Introduction to Iterators
  20.1.3 Introduction to Algorithms
20.2 Sequence Containers
  20.2.1 vector Sequence Container
  20.2.2 list Sequence Container
  20.2.3 deque Sequence Container
20.3 Associative Containers
  20.3.1 multiset Associative Container
  20.3.2 set Associative Container
  20.3.3 multimap Associative Container
  20.3.4 map Associative Container
20.4 Container Adapters
  20.4.1 stack Adapter
  20.4.2 queue Adapter
  20.4.3 priority_queue Adapter
20.5 Algorithms
  20.5.1 fill, fill_n, generate and generate_n
  20.5.2 equal, mismatch and lexicographical_compare
  20.5.3 remove, remove_if, remove_copy and remove_copy_if
  20.5.4 replace, replace_if, replace_copy and replace_copy_if
  20.5.5 Mathematical Algorithms
  20.5.6 Basic Searching and Sorting Algorithms
  20.5.7 swap, iter_swap and swap_ranges
  20.5.8 copy_backward, merge, unique and reverse
  20.5.9 inplace_merge, unique_copy and reverse_copy
  20.5.10 Set Operations
  20.5.11 lower_bound, upper_bound and equal_range
  20.5.12 Heapsort
  20.5.13 min and max
  20.5.14 STL Algorithms Not Covered in This Chapter
20.6 Class bitset
20.7 Function Objects
20.8 Wrap-Up
20.9 STL Web Resources