25.9 Custom Algorithms
If you want to write such useful functions yourself that you store them in a header for the future of your programming career and then reuse them in all projects, it is quite simple to do. Well, you will need one or two angle brackets <>, but with functions, it's not that bad. The template parameters are mainly iterators and sometimes a function or a functor.
Assume you wanted to write an algorithm that calls a function for all adjacent pairs of a container range. That is, it does something similar to std::for_each, but for two adjacent elements of the container. Then the following applies:
-
A container range is represented as usual by a pair of iterators.
-
The two iterators are of the same type and a template parameter. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access