CHAP. 15]
CONTAINER CLASSES
339
elements doesn’t matter. As the diagram shows, there are four general sequence containers: set,
multiset, map, and multimap.
The Standard C++ Library also defines three specialized container class templates:
basic_string, valarray, and bitset. These are not classified as general containers because
their operations are not as general as the others.
The vector<> template is the prototype of all the container classes. It generalizes the direct
access array, as described in Chapter 10. Most of its functions apply to the other templates.
The vector<> template is outlined in Chapter 14.
The deque<> template generalizes the stack and the queue containers. A deque (pronounced
“deck”) is a sequential container that allows insertions and deletions at both ends. Special
adapters are provided that use this template to define the stack<> template and the queue<>
template.
The list<> template generalizes the linked list structure which does not have indexed
access but does have much faster insertion and deletion operations. A special adapter uses the
list<> template to define the priority_queue<> template.
The set<> template provides containers that represent mathematical sets, using union and
intersection operations.
The multiset<> template is the same as the set<> template except that its containers
allow multiple copies elements.
The map<> template generalizes the look-up table structure. Maps are also called an associative array. The hash table data structure is a special kind of map.
The multimap<> template is the same as the map<> template except that its containers
allow multiple copies elements.
The basic_string<> template generalizes the notion of a character string, allowing strings
of any type. The common special cases are defined by typedefs:
typedef basic_string string;
typedef basic_string wstring;
The valarray<> template is intended for instantiating mathematical vectors and linear array
processing.
The bitset<> template is used for processing bitstrings: objects whose values are usually in
hexadecimal and which are operated upon by the logical operators |, &, ^, <<, and >>.
15.4 STANDARD C++ GENERIC ALGORITHMS
The Standard C++ generic algorithms are non-member functions that apply to the Standard
C++ container classes. They provide a consistent suite of tools that cover just about any application of containers. They also allow for easy transfer of elements from one type of container to
another. The details of these functions are given in Appendix D.
Two of the most useful algorithms are the find() and sort() functions. These were
illustrated in Chapter 14. (See Examples 14.4 and 14.9.) These are illustrated with other containers in the examples in this chapter.
340
CONTAINER CLASSES
[CHAP. 15
15.5 HEADER FILES
The Standard C++ container templates and generic algorithms are defined in the following
header files:
accumulate()
adjacent_difference()
adjacent_find()
basic_string<>
binary_search()
bitset<>
copy()
copy_backward()
count()
count_if()
deque<>
equal()
equal_find()
fill()
fill_n()
find_end()
find_first_of()
find_if()
for_each()
generate()
generate_n()
includes()
inner_product()
inplace_merge()
iter_swap()
lexicographic_compare()
list<>
lower_bound()
make_heap()
map<>
max()
max_element()
merge()
min()
min_element()
mismatch()
multimap<>
multiset<>
next_permutation()
nth_element()
partial_sort()
partial_sum()
partition()
partition_sort_copy()
pop_heap()
prev_permutation()
priority_queue<>