Other Associative Containers
Themultimapcontainer class is a mapclass without the restriction of unique keys. More
than one element can have the same key value.
Thesetcontainer class is also similar to the mapclass. The only difference is that its ele-
ments are not (key, value) pairs. An element is only the key. The multisetcontainer
class is a setclass that allows duplex key values.
Finally, the bitsetcontainer class is a template for storing a sequence of bits.
Working with the Algorithm Classes ............................................................
A container is a useful place to store a sequence of elements. All standard containers
define operations that manipulate the containers and their elements. Implementing all
these operations in your own sequences, however, can be laborious and prone to error.
Because most of those operations are likely to be the same in most sequences, a set of
generic algorithms can reduce the need to write your own operations for each new con-
tainer. The standard library provides approximately 60 standard algorithms that perform
the most basic and commonly used operations of containers.
Standard algorithms are defined in <algorithm>in namespace std.
To understand how the standard algorithms work, you need to understand the concept of
function objects. A function object is an instance of a class that defines the overloaded
operator(). Therefore, it can be called as a function. Listing 19.11 demonstrates a func-
tion object.
LISTING19.11 A Function Object
0: #include <iostream>
1: using namespace std;
2:
3: template<class T>
4: class Print
5: {
6: public:
7: void operator()(const T& t)
8: {
9: cout << t << “ “;
10: }
11: };
12:
13: int main()
14: {
15: Print<int> DoPrint;
16: for (int i = 0; i < 5; ++i)
708 Day 19