#include <iostream>
#include <vector>
#include <algorithm>
/*
Description:
Returns an iterator to the first element in the range [first,last) for which pred returns false.
If no such element is found, the function returns last.
Parameters:
Input iterator to inital and final position in the sequence [first,last)
Pred:
Unary function that accepts an element in the range as argument and returns a value convertible to bool.
The value returned indicates whether the element is considered a match in the context of this function.
*/
int main() {
std::vector<int> A({10,8,7,9,6,4,5,3,2,1});
//Return the first element which not greater than 5
std::vector<int>::iterator it = std::find_if_not(A.begin(),A.end(),[ ] ( auto num ) {
return num > 5 ;
});
if(it != A.end())
std::cout << "The first element which is not greater than 5 is: " << *it << std::endl;
}
/*
Compilation:
g++ <program name> -i <output file> -Wall -Werror
Output:
The first element which is not greater than 5 is: 4
*/
Comments