10.1. Overview
Most of the algorithms are defined in the algorithm
header. The library also defines a set of generic numeric algorithms that are defined in the numeric
header.
In general, the algorithms do not work directly on a container. Instead, they operate by traversing a range of elements bounded by two iterators (§ 9.2.1, p. 331). Typically, as the algorithm traverses the range, it does something with each element. For example, suppose we have a vector
of int
s and we want to know if that vector
holds a particular value. The easiest way to answer this question is to call the library find
algorithm:
int val = 42; // value we'll look for ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.