June 2025
Intermediate to advanced
1093 pages
33h 24m
English
In addition to the capabilities of the containers, there are algorithms. Most of them can be found in the <algorithm> header. There is a long list of auxiliary functions that help you to solve specific problems using general methods.
All these algorithms consistently work on iterators, which is why they work on (almost) all containers. It is important to know that the power of the containers is not exhausted by their methods.
In the following example, a vector is filled with an algorithm, and then elements meeting a specific criterion are counted.
// https://godbolt.org/z/4G67rso8T#include <vector>#include <algorithm> // count_if#include <numeric> // iota#include <iostream>bool even(int n) { return n%2==0; } // test for even ...
Read now
Unlock full access