Finding elements in a range
One of the most common operations we do in any application is searching through data. Therefore, it is not surprising that the standard library provides many generic algorithms for searching through standard containers, or anything that can represent a range and is defined by a start and a past-the-end iterator. In this recipe, we will see what these standard algorithms are and how they can be used.
For all the examples in this recipe, we will use
std::vector, but all the algorithms work with ranges defined by a begin and past-the-end, either input or forward iterators, depending on the algorithm (for more information about the various types of iterators, see the Writing your own random access iterator recipe, later in this chapter). All these algorithms are available in the
std namespace in the
How to do it...
The following is a list of algorithms that can be used for finding elements in a range:...