find_if complexity c++ code example
Example: find_if c++ example
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> myvec {2, 5, 6, 10, 56, 7, 48, 89};
vector<int>::iterator gt10 = find_if(myvec.begin(), myvec.end(), [](int x){return x>10;}); // >= C++11
cout << "First item > 10: " << *gt10 << endl;
//check if pointer points to myvec.end()
if(gt10 != myvec.end()) {
cout << "nf points to: " << *gt10 << endl;
}
else {
cout << "item not found" << endl;
}
return 0;
}