O'Reilly logo

STL Pocket Reference by Ray Lischner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Algorithms

The so-called algorithms in the standard library distinguish C++ from other programming languages. Every major programming language has a suite of container types, but in the traditional object-oriented approach, each container class defines the operations that it permits, e.g., sorting, searching, and modifying. C++ turns object-oriented programming on its head and provides a set of function templates, called algorithms, that work with iterators, and therefore with almost any container.

Most of the standard algorithms are declared in the <algorithm> header, with some numerical algorithms in <numeric>, and a few algorithms in <memory> for working with uninitialized buffers. Unless otherwise mentioned, the function templates in this section are declared in <algorithm>. This section organizes the algorithms in groups of related functions. To find a specific algorithm by name, check the index.

The type of every function parameter in this section is a type template parameter. For the sake of brevity, the template header is omitted from each declaration. The compiler usually deduces the template parameter types. If you must specify an explicit template argument, the order of the template parameters matches the order of their use in the function parameters.

The names of the template parameters tell you what kind of template argument is expected, especially the iterator category. The iterator category is the minimal functionality needed, so you can, for example, use a random access ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required