I wrote a version of find_all() which searches through containers for matches and returns another container that holds iterators pointing to each match. When I compared what I wrote to what the authors of Professional C++ wrote, I found the two find_all() functions to be very different. I would like your help in comparing my and their functions. Here they are:
//Mine
template<typename Iterator, typename Predicate>
std::list<Iterator> find_all
(Iterator front, Iterator back, const Predicate& match)
{
std::list<Iterator> toreturn;
for(; front != back; ++front) if(*front == match) toreturn.push_back(front);
return toreturn;
}
//Verbatim from Professional C++template <typename InputIterator, typename Predicate>
vector<InputIterator>
find_all(InputIterator first, InputIterator last, Predicate pred)
{
vector<InputIterator> res;
while(true) {
// Find the next match in the current range.
first = find_if(first, last, pred);
// check if find_if failed to find a match
if (first == last) {
break;
}
// Store this match.
res.push_back(first);
// Shorten the range to start at one past the current match
++first;
}
return res;
}