[Home]STLAlgorithmExtensions/AllAlgorithm

BOOST WIKI | STLAlgorithmExtensions | RecentChanges | Preferences | Page List | Links List

This algorithm returns true if the predicate is true for all elements in the range.
template <typename InputIterator, typename Predicate>
bool all(InputIterator first, InputIterator last, Predicate p)
{
  for (; first != last; ++first)
    if (!p(*first))
      return false;
  return true;
}

Couldn't this be more simply stated as:
template <typename InputIterator, typename Predicate>
bool all_if(InputIterator first, InputIterator last, Predicate p) {
  return std::find_if(first, last, std::not1(p)) == last;
}

?


That would require p to be an adaptable predicate (e.g. derive from std::unary_function). It's the same problem as with copy_if.
BOOST WIKI | STLAlgorithmExtensions | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited September 29, 2004 8:45 pm (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers