#include <algorithm>
#include <iostream>
int main()
{// 0 1 2 3 4
int myArray[] = {1, 1, 1, 5, 1};
int * beginIter = &myArray[0];
int * endIter = &myArray[5];
int * iter = std::find_if_not(beginIter, endIter,
[](int element){return element == 1;});
if (iter != endIter)
{
std::cout << *iter << " ";
}
else
{
std::cout << "Did not find anything ";
}
myArray[3] = 1;
iter = std::find_if_not(beginIter, endIter,
[](int element){return element == 1;});
if (iter != endIter)
{
std::cout << *iter << " ";
}
else
{
std::cout << "Did not find anything ";
}
std::cout << std::endl;
return 0;
}
// Output: 5 Did not find anything
Reference: https://isocpp.org/wiki/faq/cpp11-library-stl#cpp11-algorithms
Friday, September 1, 2017
C++11: Algorithms: find_if_not
The find_if_not algorithm was added. Here is an example:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment