std::all_of() in C++
The C++ function is defined in <algorithm> library in STL. This function operates on whole range of array elements and can save time to run a loop to check each elements one by one. It checks for a given property on every element and returns true when each element in range satisfies specified property, else returns false.
template <class InputIterator, class UnaryPredicate> bool all_of (InputIterator first, InputIterator last, UnaryPredicate pred); first : Input iterators to the initial positions in a sequence. last : Input iterators to the final positions in a sequence. pred : An unary predicate function that accepts an element and returns a bool.
Exception : Throws exception if either predicate or an operation on an iterator throws exception.
All numbers are even
All are not positive elements
In the above code, -6 being a negative element negates the condition and returns false.
This article is contributed by Manjeet Singh . If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.