June 2025
Intermediate to advanced
1093 pages
33h 24m
English
In the standard library, you will find function templates everywhere. You have already seen some examples, especially from the <algorithm> and <numeric> headers.
The functions from these headers are particularly interesting because they work with the standard containers. If you pass an entire container as a parameter, starting from C++20, it becomes a range (see Chapter 24, Section 24.1.7). Alternatively—and before C++20—you pass a pair of iterators, as in the next listing.
// https://godbolt.org/z/oTn1K4sGG#include <vector>#include <iostream> // cout, ostream#include <algorithm> // sort, copy#include <iterator> // ostream_iteratorint main() { std::ostream_iterator<int> oit(std::cout," ");
Read now
Unlock full access