C++ Algorithm Function any_of()Last Updated : 17 Mar 2025 C++ Algorithm any_of() function tests the value of 'pred' for every element in the range, if for any element the value of pred is true, then the function returns true else return false. SyntaxParameterfirst: It is the first element in the range specified. last: It is the last element in the range. pred: It is a unary function which accepts the argument from the range. Return valueThe function has one return type, 'true'. If the value of argument 'pred' is true for any of the elements of the range then the value 'true' is returned, else false. Example 1Output: There are elements which exist in the table of 2. Example 2Output: Negative elements exist in the array ComplexityThe function moves linearly, starting from the first element going towards the last one. For each element of the list, the value of 'pred' is checked. The search goes on until a mismatch for the 'pred' value is encountered. Data racesEither the function accesses all the objects in the specified range or some of them. ExceptionsThe function throws an exception if any of the argument throws one. Next TopicC++ Algorithm copy Function |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India