C++ Standard Algorithms: <algorithm>
Template functions allow many common operations to be written once for different types. The standard algorithms all operate on sequences, rather than containers (see the section “Finding Items” in Chapter 3 for the reasons why). For example, to specify all elements of a container c you can use c.begin(),c.end(). Because the containers have the same basic interface (for instance, they all have begin() and end()) it is possible to write code that will work whether you are using list, vector, or any other standard container.
Many of the standard algorithms are very straightforward template functions. Most of them are simple loops. Here is a implementation of for_each(), copy(), and transform():
template <class ...
Get C++ By Example: UnderC Learning 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.