std::all_of, std::any_of, std::none_of
From Cppreference
| Defined in header
<algorithm> | ||
| template< class InputIterator, class UnaryPredicate >
bool all_of( InputIterator first, InputIterator last, UnaryPredicate p ); | (C++0x feature) | |
| template< class InputIterator, class UnaryPredicate >
bool any_of( InputIterator first, InputIterator last, UnaryPredicate p ); | (C++0x feature) | |
| template< class InputIterator, class UnaryPredicate >
bool none_of( InputIterator first, InputIterator last, UnaryPredicate p ); | (C++0x feature) | |
1) Checks if unary predicate p returns true for all elements in the range [first, last).
2) Checks if unary predicate p returns true for at least one element in the range [first, last).
3) Checks if unary predicate p returns true for none elements in the range [first, last).
Contents |
Parameters
| first, last | - | the range of elements to examine | |||||||||
| p | - | unary predicate . The signature of the predicate function should be equivalent to the following:
The signature does not need to have const &, but the function must not modify the objects passed to it. | |||||||||
Return value
true if unary predicate returns true for all elements in the range, false otherwise.
Complexity
linear in the distance between first and last
Equivalent function
| First version: |
|---|
template< class InputIterator, class UnaryPredicate > InputIterator all_of(InputIterator first, InputIterator last, UnaryPredicate p) { for (; first != last; ++first) { if (!p(*first)) return false; } return true; } |
| Second version: |
template< class InputIterator, class UnaryPredicate > InputIterator any_of(InputIterator first, InputIterator last, UnaryPredicate p) { for (; first != last; ++first) { if (p(*first)) return true; } return false; } |
| Third version: |
template< class InputIterator, class UnaryPredicate > InputIterator none_of(InputIterator first, InputIterator last, UnaryPredicate p) { for (; first != last; ++first) { if (p(*first)) return false; } return true; } |
Example
| This section is incomplete |