VOOZH about

URL: https://www.geeksforgeeks.org/cpp/stdfind_if-stdfind_if_not-in-c/

⇱ std::find_if , std::find_if_not in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

std::find_if , std::find_if_not in C++

Last Updated : 21 Aug, 2025

std :: find_if and std :: find_if_not are algorithm functions in C++ Standard Library in <algorithm> header file. These functions provide an efficient way to search for an element in a container using a predicate function.

std :: find_if

This function returns an iterator to the first element in the range [first, last) for which pred(Unary Function) returns true. If no such element is found, the function returns last.

Syntax

InputIterator find_if (InputIterator first, InputIterator last, UnaryPredicate pred);

Parameters

  • first, last: range which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
  • pred: Unary function that accepts an element in the range as an argument and returns a value in boolean.

Return Value

  • This function returns an iterator to the first element in the range [first, last) for which pred(function) returns true. If no such element is found, the function returns last.

Example

The following C++ program illustrates the use of the find_if() function.


Output
The first odd value is 25

std :: find_if_not

This function returns an iterator to the first element in the range [first, last) for which pred(Unary Function) returns false. If no such element is found, the function returns last.

Syntax

InputIterator find_if_not (InputIterator first, InputIterator last, UnaryPredicate pred);

Parameters

  • first, last: range which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.
  • pred: Unary function that accepts an element in the range as an argument and returns a value in boolean.

Return value

  • This function returns an iterator to the first element in the range [first, last) for which pred(function) returns false.

Example

The following C++ program illustrates the use of the find_if_not() function.


Output
The first non-odd(or even) value is 10

Related Articles: 

Comment
Article Tags: