diff --git a/docs/standard-library/algorithm-functions.md b/docs/standard-library/algorithm-functions.md index 9b2b31f092b..b00d59a418d 100644 --- a/docs/standard-library/algorithm-functions.md +++ b/docs/standard-library/algorithm-functions.md @@ -203,6 +203,40 @@ The template function returns **true** only if, for some `N` in the range `[0, last - first)`, the predicate `comp(*(first + N))` is true. +### Example + +```cpp +// alg_any_of.cpp +// compile with: /EHsc +#include +#include +#include + +int main() +{ + using namespace std; + + list li { 51, 41, 11, 21, 20 }; + + cout << "li = ( "; + for (auto const& el : li) + cout << el << " "; + cout << ")" << endl; + + // Check if there is an even elememt in li. + auto is_even = [](int const elem){ return !(elem % 2); }; + if (any_of(li.begin(), li.end(), is_even)) + cout << "There's an even element in li.\n"; + else + cout << "There are no even elements in li.\n"; +} +``` + +```Output +L = ( 51 41 11 21 20 ) +There's an even element in li. +``` + ## binary_search Tests whether there is an element in a sorted range that is equal to a specified value or that is equivalent to it in a sense specified by a binary predicate.