Finding Elements in an STL map or multimap ................................................538
Erasing Elements from an STL
map or multimap ............................................540
Supplying a Custom Sort Predicate
........................................................................543
Summary
..........................................................................................................547
Q&A
................................................................................................................547
Workshop
........................................................................................................548
PART IV: More STL
LESSON 22: Understanding Function Objects 553
The Concept of Function Objects and Predicates......................................................554
Typical Applications of Function Objects
................................................................554
Unary Functions
........................................................................................554
Unary Predicate
........................................................................................559
Binary Functions
......................................................................................561
Binary Predicate
........................................................................................563
Summary
..........................................................................................................566
Q&A
................................................................................................................566
Workshop
........................................................................................................567
LESSON 23: STL Algorithms 569
What Are STL Algorithms?..................................................................................570
Classification of STL Algorithms
..........................................................................570
Nonmutating Algorithms
............................................................................570
Mutating Algorithms
..................................................................................571
Usage of STL Algorithms
....................................................................................573
Counting and Finding Elements
..................................................................573
Searching for an Element or a Range in a Collection
........................................576
Initializing Elements in a Container to a Specific Value
....................................578
Processing Elements in a Range Using
for_each............................................581
Performing Transformations on a Range Using
std::transform ......................583
Copy and Remove Operations
......................................................................585
Replacing Values and Replacing Element Given a Condition
............................589
Sorting and Searching in a Sorted Collection, and Erasing Duplicates
................591
Partitioning a Range
..................................................................................593
Inserting Elements in a Sorted Collection
......................................................595
Summary
..........................................................................................................598
Contents
xvii